github.com/aavshr/aws-sdk-go@v1.41.3/aws/client/client.go (about) 1 package client 2 3 import ( 4 "fmt" 5 6 "github.com/aavshr/aws-sdk-go/aws" 7 "github.com/aavshr/aws-sdk-go/aws/client/metadata" 8 "github.com/aavshr/aws-sdk-go/aws/request" 9 ) 10 11 // A Config provides configuration to a service client instance. 12 type Config struct { 13 Config *aws.Config 14 Handlers request.Handlers 15 PartitionID string 16 Endpoint string 17 SigningRegion string 18 SigningName string 19 20 // States that the signing name did not come from a modeled source but 21 // was derived based on other data. Used by service client constructors 22 // to determine if the signin name can be overridden based on metadata the 23 // service has. 24 SigningNameDerived bool 25 } 26 27 // ConfigProvider provides a generic way for a service client to receive 28 // the ClientConfig without circular dependencies. 29 type ConfigProvider interface { 30 ClientConfig(serviceName string, cfgs ...*aws.Config) Config 31 } 32 33 // ConfigNoResolveEndpointProvider same as ConfigProvider except it will not 34 // resolve the endpoint automatically. The service client's endpoint must be 35 // provided via the aws.Config.Endpoint field. 36 type ConfigNoResolveEndpointProvider interface { 37 ClientConfigNoResolveEndpoint(cfgs ...*aws.Config) Config 38 } 39 40 // A Client implements the base client request and response handling 41 // used by all service clients. 42 type Client struct { 43 request.Retryer 44 metadata.ClientInfo 45 46 Config aws.Config 47 Handlers request.Handlers 48 } 49 50 // New will return a pointer to a new initialized service client. 51 func New(cfg aws.Config, info metadata.ClientInfo, handlers request.Handlers, options ...func(*Client)) *Client { 52 svc := &Client{ 53 Config: cfg, 54 ClientInfo: info, 55 Handlers: handlers.Copy(), 56 } 57 58 switch retryer, ok := cfg.Retryer.(request.Retryer); { 59 case ok: 60 svc.Retryer = retryer 61 case cfg.Retryer != nil && cfg.Logger != nil: 62 s := fmt.Sprintf("WARNING: %T does not implement request.Retryer; using DefaultRetryer instead", cfg.Retryer) 63 cfg.Logger.Log(s) 64 fallthrough 65 default: 66 maxRetries := aws.IntValue(cfg.MaxRetries) 67 if cfg.MaxRetries == nil || maxRetries == aws.UseServiceDefaultRetries { 68 maxRetries = DefaultRetryerMaxNumRetries 69 } 70 svc.Retryer = DefaultRetryer{NumMaxRetries: maxRetries} 71 } 72 73 svc.AddDebugHandlers() 74 75 for _, option := range options { 76 option(svc) 77 } 78 79 return svc 80 } 81 82 // NewRequest returns a new Request pointer for the service API 83 // operation and parameters. 84 func (c *Client) NewRequest(operation *request.Operation, params interface{}, data interface{}) *request.Request { 85 return request.New(c.Config, c.ClientInfo, c.Handlers, c.Retryer, operation, params, data) 86 } 87 88 // AddDebugHandlers injects debug logging handlers into the service to log request 89 // debug information. 90 func (c *Client) AddDebugHandlers() { 91 c.Handlers.Send.PushFrontNamed(LogHTTPRequestHandler) 92 c.Handlers.Send.PushBackNamed(LogHTTPResponseHandler) 93 }