github.com/oam-dev/cluster-gateway@v1.9.0/pkg/apis/cluster/transport/context.go (about)

     1  package multicluster
     2  
     3  import "context"
     4  
     5  type contextKey string
     6  
     7  const (
     8  	// ClusterContextKey is the name of cluster using in client http context
     9  	clusterContextKey = contextKey("ClusterName")
    10  )
    11  
    12  func WithMultiClusterContext(ctx context.Context, clusterName string) context.Context {
    13  	return context.WithValue(ctx, clusterContextKey, clusterName)
    14  }
    15  
    16  func GetMultiClusterContext(ctx context.Context) (string, bool) {
    17  	clusterName, ok := ctx.Value(clusterContextKey).(string)
    18  	return clusterName, ok
    19  }