context.go 282 B

1234567891011121314
  1. package thoth
  2. import "context"
  3. type ctxKey struct{}
  4. func With(ctx context.Context, cli *Client) context.Context {
  5. return context.WithValue(ctx, ctxKey{}, cli)
  6. }
  7. func FromContext(ctx context.Context) (*Client, bool) {
  8. cli, ok := ctx.Value(ctxKey{}).(*Client)
  9. return cli, ok
  10. }