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.

27 lines
609 B

2 years ago
package middleware
import (
"context"
"fmt"
"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) {
fmt.Println("add_header_md")
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)
}
}
}