src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

context.go (1403B)


      1 package middleware
      2 
      3 import "context"
      4 
      5 type (
      6 	serviceIDKey     struct{}
      7 	operationNameKey struct{}
      8 )
      9 
     10 // WithServiceID adds a service ID to the context, scoped to middleware stack
     11 // values.
     12 //
     13 // This API is called in the client runtime when bootstrapping an operation and
     14 // should not typically be used directly.
     15 func WithServiceID(parent context.Context, id string) context.Context {
     16 	return WithStackValue(parent, serviceIDKey{}, id)
     17 }
     18 
     19 // GetServiceID retrieves the service ID from the context. This is typically
     20 // the service shape's name from its Smithy model. Service clients for specific
     21 // systems (e.g. AWS SDK) may use an alternate designated value.
     22 func GetServiceID(ctx context.Context) string {
     23 	id, _ := GetStackValue(ctx, serviceIDKey{}).(string)
     24 	return id
     25 }
     26 
     27 // WithOperationName adds the operation name to the context, scoped to
     28 // middleware stack values.
     29 //
     30 // This API is called in the client runtime when bootstrapping an operation and
     31 // should not typically be used directly.
     32 func WithOperationName(parent context.Context, id string) context.Context {
     33 	return WithStackValue(parent, operationNameKey{}, id)
     34 }
     35 
     36 // GetOperationName retrieves the operation name from the context. This is
     37 // typically the operation shape's name from its Smithy model.
     38 func GetOperationName(ctx context.Context) string {
     39 	name, _ := GetStackValue(ctx, operationNameKey{}).(string)
     40 	return name
     41 }