Skip to content

Instantly share code, notes, and snippets.

@sang-w0o
Last active February 28, 2022 09:04
Show Gist options
  • Save sang-w0o/28faf303b9e7eaf02fa8a49532f64ab9 to your computer and use it in GitHub Desktop.
Save sang-w0o/28faf303b9e7eaf02fa8a49532f64ab9 to your computer and use it in GitHub Desktop.
grpc_gateway_3.go
func setContextFromMetadata(ctx context.Context) (context.Context, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
// handle error
}
data := md.Get("value1")
if len(data) == 0 {
return nil, fmt.Errorf("some error occured.")
}
value1 := data[0]
data = md.Get("value2")
if len(data) == 0 {
return nil, fmt.Errorf("some error occured.")
}
value2 := data[0]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment