You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
570 B
24 lines
570 B
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) |
|
} |
|
} |
|
}
|
|
|