hackathon/api/metadata.go

31 lines
395 B
Go

package api
import (
"context"
"strings"
"google.golang.org/grpc/metadata"
)
type MD metadata.MD
func RequestMetadata(ctx context.Context) MD {
m, ok := metadata.FromIncomingContext(ctx)
if !ok {
return nil
}
return MD(m)
}
func (md MD) Get(k string) string {
if md == nil {
return ""
}
k = strings.ToLower(k)
if res := md[k]; len(res) > 0 {
return res[0]
}
return ""
}