context.go 1.4 KB

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