service.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
  2. package s3
  3. import (
  4. "github.com/aws/aws-sdk-go/aws"
  5. "github.com/aws/aws-sdk-go/aws/client"
  6. "github.com/aws/aws-sdk-go/aws/client/metadata"
  7. "github.com/aws/aws-sdk-go/aws/request"
  8. "github.com/aws/aws-sdk-go/aws/signer/v4"
  9. "github.com/aws/aws-sdk-go/private/protocol/restxml"
  10. )
  11. // S3 is a client for Amazon S3.
  12. // The service client's operations are safe to be used concurrently.
  13. // It is not safe to mutate any of the client's properties though.
  14. // Please also see https://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01
  15. type S3 struct {
  16. *client.Client
  17. }
  18. // Used for custom client initialization logic
  19. var initClient func(*client.Client)
  20. // Used for custom request initialization logic
  21. var initRequest func(*request.Request)
  22. // Service information constants
  23. const (
  24. ServiceName = "s3" // Service endpoint prefix API calls made to.
  25. EndpointsID = ServiceName // Service ID for Regions and Endpoints metadata.
  26. )
  27. // New creates a new instance of the S3 client with a session.
  28. // If additional configuration is needed for the client instance use the optional
  29. // aws.Config parameter to add your extra config.
  30. //
  31. // Example:
  32. // // Create a S3 client from just a session.
  33. // svc := s3.New(mySession)
  34. //
  35. // // Create a S3 client with additional configuration
  36. // svc := s3.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
  37. func New(p client.ConfigProvider, cfgs ...*aws.Config) *S3 {
  38. c := p.ClientConfig(EndpointsID, cfgs...)
  39. return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
  40. }
  41. // newClient creates, initializes and returns a new service client instance.
  42. func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *S3 {
  43. svc := &S3{
  44. Client: client.New(
  45. cfg,
  46. metadata.ClientInfo{
  47. ServiceName: ServiceName,
  48. SigningName: signingName,
  49. SigningRegion: signingRegion,
  50. Endpoint: endpoint,
  51. APIVersion: "2006-03-01",
  52. },
  53. handlers,
  54. ),
  55. }
  56. // Handlers
  57. svc.Handlers.Sign.PushBackNamed(v4.SignRequestHandler)
  58. svc.Handlers.Build.PushBackNamed(restxml.BuildHandler)
  59. svc.Handlers.Unmarshal.PushBackNamed(restxml.UnmarshalHandler)
  60. svc.Handlers.UnmarshalMeta.PushBackNamed(restxml.UnmarshalMetaHandler)
  61. svc.Handlers.UnmarshalError.PushBackNamed(restxml.UnmarshalErrorHandler)
  62. // Run custom client initialization if present
  63. if initClient != nil {
  64. initClient(svc.Client)
  65. }
  66. return svc
  67. }
  68. // newRequest creates a new request for a S3 operation and runs any
  69. // custom request initialization.
  70. func (c *S3) newRequest(op *request.Operation, params, data interface{}) *request.Request {
  71. req := c.NewRequest(op, params, data)
  72. // Run custom request initialization if present
  73. if initRequest != nil {
  74. initRequest(req)
  75. }
  76. return req
  77. }