如何在grpc中读取服务器端的元数据(作为标题传递)?golang的任何一个例子?
我写的是这样的:
// this should be passed from the client side as a context and needs to accessed on server side to read the metadata
var headers = metadata.New(map[string]string{"authorization": "", "space": "", "org": "", "limit": "", "offset": ""})
Run Code Online (Sandbox Code Playgroud)
我想将授权令牌传递给我的验证函数以验证收到的令牌.
func validate_token(ctx context.Context, md *metadata.MD) (context.Context, error){
token := headers["authorization"]
}
Run Code Online (Sandbox Code Playgroud) 试着结识去吧.我想做这样的事情:
func validation(){
headers := metadata.New(map[string]string{"auth":"", "abc": "", "xyz" : ""})
token := headers["auth"]
data.Add("cookie", token)
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:cannot use token (type []string) as type string in argument to data.Add.这个错误是否与我在函数内部的元数据(map)有关?