選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

20 行
442 B

  1. package middleware
  2. import (
  3. "context"
  4. "github.com/QuantumNous/new-api/common"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func RequestId() func(c *gin.Context) {
  8. return func(c *gin.Context) {
  9. id := common.GetTimeString() + common.GetRandomString(8)
  10. c.Set(common.RequestIdKey, id)
  11. ctx := context.WithValue(c.Request.Context(), common.RequestIdKey, id)
  12. c.Request = c.Request.WithContext(ctx)
  13. c.Header(common.RequestIdKey, id)
  14. c.Next()
  15. }
  16. }