S
S
SSSSTTTTAAAASSSS2021-09-25 08:52:04
go
SSSSTTTTAAAASSSS, 2021-09-25 08:52:04

GRPC context.WithValue?

Good afternoon.
I can't figure out why when my gRPC client sends a request to the server with the context.WithValue context, my server can't parse it?
Despite the fact that this context goes to the client along the entire chain and it is logged, and when it is received by the server that sends it further, it also stops parsing.
So far, from the ideas, this is only when the client receives the context, push it into the metadata and only then send the request to the server, and it will, in turn, re-push it back into the normal context and send it to the service and the database. But this seems like the wrong decision.
Perhaps there is some other way?
Thanks in advance for your help.

here is the gRPC client method
```
func (s UserGRPCController) CreateUser(ctx context.Context, name string) (uuid.UUID, error) {
id, ok := ctx.Value(model.ContextKeyRequestID).(string) // everything is ok here, and the context is parsed
if !ok {
log.Info("failed to convert context value and get context id")
}
resp, err := s.client.Create(ctx, &pb.Name{Name: name, })
....... .
}
```

server method that is no longer parsed
```
func (s UserServerGRPC) Create(ctx context.Context, in *pb.Name) (*pb.User, error) {
id, ok := ctx.Value (model.ContextKeyRequestID).(string) // here the context is not parsed and then it goes empty
if !ok {
log.Info("failed to convert context value and get context id")
}
res, err := s.service.Create(ctx, in.Name)
.....
}
```

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Papa, 2021-09-25
@SSSSTTTTAAAASSSS

Here's the answer to the question: https://www.hward.com/golang-grpc-context-client-s...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question