github.com/aavshr/aws-sdk-go@v1.41.3/service/s3/service.go (about)

     1  // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
     2  
     3  package s3
     4  
     5  import (
     6  	"github.com/aavshr/aws-sdk-go/aws"
     7  	"github.com/aavshr/aws-sdk-go/aws/client"
     8  	"github.com/aavshr/aws-sdk-go/aws/client/metadata"
     9  	"github.com/aavshr/aws-sdk-go/aws/request"
    10  	"github.com/aavshr/aws-sdk-go/aws/signer/v4"
    11  	"github.com/aavshr/aws-sdk-go/private/protocol/restxml"
    12  )
    13  
    14  // S3 provides the API operation methods for making requests to
    15  // Amazon Simple Storage Service. See this package's package overview docs
    16  // for details on the service.
    17  //
    18  // S3 methods are safe to use concurrently. It is not safe to
    19  // modify mutate any of the struct's properties though.
    20  type S3 struct {
    21  	*client.Client
    22  }
    23  
    24  // Used for custom client initialization logic
    25  var initClient func(*client.Client)
    26  
    27  // Used for custom request initialization logic
    28  var initRequest func(*request.Request)
    29  
    30  // Service information constants
    31  const (
    32  	ServiceName = "s3"        // Name of service.
    33  	EndpointsID = ServiceName // ID to lookup a service endpoint with.
    34  	ServiceID   = "S3"        // ServiceID is a unique identifier of a specific service.
    35  )
    36  
    37  // New creates a new instance of the S3 client with a session.
    38  // If additional configuration is needed for the client instance use the optional
    39  // aws.Config parameter to add your extra config.
    40  //
    41  // Example:
    42  //     mySession := session.Must(session.NewSession())
    43  //
    44  //     // Create a S3 client from just a session.
    45  //     svc := s3.New(mySession)
    46  //
    47  //     // Create a S3 client with additional configuration
    48  //     svc := s3.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
    49  func New(p client.ConfigProvider, cfgs ...*aws.Config) *S3 {
    50  	c := p.ClientConfig(EndpointsID, cfgs...)
    51  	if c.SigningNameDerived || len(c.SigningName) == 0 {
    52  		c.SigningName = "s3"
    53  	}
    54  	return newClient(*c.Config, c.Handlers, c.PartitionID, c.Endpoint, c.SigningRegion, c.SigningName)
    55  }
    56  
    57  // newClient creates, initializes and returns a new service client instance.
    58  func newClient(cfg aws.Config, handlers request.Handlers, partitionID, endpoint, signingRegion, signingName string) *S3 {
    59  	svc := &S3{
    60  		Client: client.New(
    61  			cfg,
    62  			metadata.ClientInfo{
    63  				ServiceName:   ServiceName,
    64  				ServiceID:     ServiceID,
    65  				SigningName:   signingName,
    66  				SigningRegion: signingRegion,
    67  				PartitionID:   partitionID,
    68  				Endpoint:      endpoint,
    69  				APIVersion:    "2006-03-01",
    70  			},
    71  			handlers,
    72  		),
    73  	}
    74  
    75  	// Handlers
    76  	svc.Handlers.Sign.PushBackNamed(v4.BuildNamedHandler(v4.SignRequestHandler.Name, func(s *v4.Signer) {
    77  		s.DisableURIPathEscaping = true
    78  	}))
    79  	svc.Handlers.Build.PushBackNamed(restxml.BuildHandler)
    80  	svc.Handlers.Unmarshal.PushBackNamed(restxml.UnmarshalHandler)
    81  	svc.Handlers.UnmarshalMeta.PushBackNamed(restxml.UnmarshalMetaHandler)
    82  	svc.Handlers.UnmarshalError.PushBackNamed(restxml.UnmarshalErrorHandler)
    83  
    84  	svc.Handlers.BuildStream.PushBackNamed(restxml.BuildHandler)
    85  	svc.Handlers.UnmarshalStream.PushBackNamed(restxml.UnmarshalHandler)
    86  
    87  	// Run custom client initialization if present
    88  	if initClient != nil {
    89  		initClient(svc.Client)
    90  	}
    91  
    92  	return svc
    93  }
    94  
    95  // newRequest creates a new request for a S3 operation and runs any
    96  // custom request initialization.
    97  func (c *S3) newRequest(op *request.Operation, params, data interface{}) *request.Request {
    98  	req := c.NewRequest(op, params, data)
    99  
   100  	// Run custom request initialization if present
   101  	if initRequest != nil {
   102  		initRequest(req)
   103  	}
   104  
   105  	return req
   106  }