package middleware import ( "context" "github.com/gin-gonic/gin" "google.golang.org/grpc/metadata" ) func AddHeaderMdMiddle(c *gin.Context) Middleware { return func(handler Handler) Handler { return func(ctx context.Context, a any) (any, error) { headers := metadata.MD{} headers1 := c.Request.Header.Clone() for k, v := range headers1 { headers.Set(k, v[0]) } headers["remote_ip"] = []string{c.RemoteIP()} headers["full_path"] = []string{c.FullPath()} ctx = metadata.NewIncomingContext(ctx, headers) return handler(ctx, a) } } }