github.com/annwntech/go-micro/v2@v2.9.5/client/context.go (about)

     1  package client
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  type clientKey struct{}
     8  
     9  func FromContext(ctx context.Context) (Client, bool) {
    10  	c, ok := ctx.Value(clientKey{}).(Client)
    11  	return c, ok
    12  }
    13  
    14  func NewContext(ctx context.Context, c Client) context.Context {
    15  	return context.WithValue(ctx, clientKey{}, c)
    16  }