context.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package context
  2. import (
  3. "context"
  4. "time"
  5. "github.com/aws/smithy-go/middleware"
  6. )
  7. type s3BackendKey struct{}
  8. type checksumInputAlgorithmKey struct{}
  9. type clockSkew struct{}
  10. const (
  11. // S3BackendS3Express identifies the S3Express backend
  12. S3BackendS3Express = "S3Express"
  13. )
  14. // SetS3Backend stores the resolved endpoint backend within the request
  15. // context, which is required for a variety of custom S3 behaviors.
  16. func SetS3Backend(ctx context.Context, typ string) context.Context {
  17. return middleware.WithStackValue(ctx, s3BackendKey{}, typ)
  18. }
  19. // GetS3Backend retrieves the stored endpoint backend within the context.
  20. func GetS3Backend(ctx context.Context) string {
  21. v, _ := middleware.GetStackValue(ctx, s3BackendKey{}).(string)
  22. return v
  23. }
  24. // SetChecksumInputAlgorithm sets the request checksum algorithm on the
  25. // context.
  26. func SetChecksumInputAlgorithm(ctx context.Context, value string) context.Context {
  27. return middleware.WithStackValue(ctx, checksumInputAlgorithmKey{}, value)
  28. }
  29. // GetChecksumInputAlgorithm returns the checksum algorithm from the context.
  30. func GetChecksumInputAlgorithm(ctx context.Context) string {
  31. v, _ := middleware.GetStackValue(ctx, checksumInputAlgorithmKey{}).(string)
  32. return v
  33. }
  34. // SetAttemptSkewContext sets the clock skew value on the context
  35. func SetAttemptSkewContext(ctx context.Context, v time.Duration) context.Context {
  36. return middleware.WithStackValue(ctx, clockSkew{}, v)
  37. }
  38. // GetAttemptSkewContext gets the clock skew value from the context
  39. func GetAttemptSkewContext(ctx context.Context) time.Duration {
  40. x, _ := middleware.GetStackValue(ctx, clockSkew{}).(time.Duration)
  41. return x
  42. }