Hi. i have func like func AAA(ctx context.Context, req interface{}) error {}
inside func i need to return some value not via error, but in context
(as i only one way do do that)
I'm write something like code below. I can't transfer code inside
error, because it predefined struct (generated from protobuf) and i
cant use grpc Outcoming context and grpc as this is not grpc
server/client code.
What the best way? And the next question - does it possible to clone
context with all deadlines and internal stuff without creating some
struct that satisfies context and uses in as parentheses?

```go
type rspCodeKey struct{}
type rspCodeVal struct {
  code int
}

func SetRspCode(ctx context.Context, code int) {
  if rsp, ok := ctx.Value(rspCodeKey{}).(*rspCodeVal); ok {
    rsp.code = code
  }
}

func GetRspCode(ctx context.Context) int {
  var code int
  if rsp, ok := ctx.Value(rspCodeKey{}).(*rspCodeVal); ok {
    code = rsp.code
  }
  return code
}
```

-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CACaajQviZSyY5V0DQWRrSCh0FQm8_wJv56b6hmUL%2B1mgLSFm9Q%40mail.gmail.com.

Reply via email to