stack-labs / questions

任何关于Micro的问题都可以在Issue中创建
27 stars 6 forks source link

网关 添加一些数据到context中,micro会序列化到header中 透传下去吗 #9

Open json7 opened 4 years ago

json7 commented 4 years ago

也可以自己直接写入到header透传下去,但是感觉通过context更优雅. 如果没有这个机制,建议加上

printfcoder commented 4 years ago

可以,比如:

        ctx := metadata.NewContext(context.Background(), map[string]string{
        "X-User-Id": "john",
        "X-From-Id": "script",
    })

    rsp, err := cl.Hello(ctx, &pb.Request{
        Name: "John",
    })