Request ID (请求ID) 中间件

Request ID 中间件为请求生成唯一的 ID。

用法

  1. e.Use(middleware.RequestID())

自定义配置

用法

  1. e.Use(middleware.RequestIDWithConfig(middleware.RequestIDConfig{
  2. Generator: func() string {
  3. return customGenerator()
  4. },
  5. }))

配置

  1. RequestIDConfig struct {
  2. // Skipper defines a function to skip middleware.
  3. Skipper Skipper
  4. // Generator defines a function to generate an ID.
  5. // Optional. Default value random.String(32).
  6. Generator func() string
  7. }

默认配置

  1. DefaultRequestIDConfig = RequestIDConfig{
  2. Skipper: DefaultSkipper,
  3. Generator: generator,
  4. }