github.com/blend/go-sdk@v1.20220411.3/grpcutil/method.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package grpcutil
     9  
    10  import "context"
    11  
    12  type methodKey struct{}
    13  
    14  // WithMethod adds a method to a context as a value.
    15  func WithMethod(ctx context.Context, fullMethod string) context.Context {
    16  	return context.WithValue(ctx, methodKey{}, fullMethod)
    17  }
    18  
    19  // GetMethod returns the rpc method from the context.
    20  func GetMethod(ctx context.Context) string {
    21  	if typed, ok := ctx.Value(methodKey{}).(string); ok {
    22  		return typed
    23  	}
    24  	return ""
    25  }