小编San*_*ket的帖子

如何在服务器端读取grpc中的元数据?(golang例子)

如何在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)

go grpc

6
推荐指数
2
解决办法
8721
查看次数

Go error:不能在参数中使用参数(type [] string)作为类型字符串

试着结识去吧.我想做这样的事情:

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)有关?

go grpc

1
推荐指数
1
解决办法
3471
查看次数

标签 统计

go ×2

grpc ×2