2 Star 0 Fork 174

hxchjm / go-zero

forked from kevwan / go-zero 
Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
carrier.go 723 Bytes
Copy Edit Raw Blame History
kevwan authored 2020-07-26 17:09 . initial import
package trace
import (
"errors"
"net/http"
"strings"
)
var ErrInvalidCarrier = errors.New("invalid carrier")
type (
Carrier interface {
Get(key string) string
Set(key, value string)
}
httpCarrier http.Header
// grpc metadata takes keys as case insensitive
grpcCarrier map[string][]string
)
func (h httpCarrier) Get(key string) string {
return http.Header(h).Get(key)
}
func (h httpCarrier) Set(key, val string) {
http.Header(h).Set(key, val)
}
func (g grpcCarrier) Get(key string) string {
if vals, ok := g[strings.ToLower(key)]; ok && len(vals) > 0 {
return vals[0]
} else {
return ""
}
}
func (g grpcCarrier) Set(key, val string) {
key = strings.ToLower(key)
g[key] = append(g[key], val)
}

Comment ( 0 )

Sign in for post a comment

Go
1
https://gitee.com/hxchjm/go-zero.git
git@gitee.com:hxchjm/go-zero.git
hxchjm
go-zero
go-zero
3eb88c4e4bf1

Search

105716 1d94204e 1850385 105716 2d26be5c 1850385