1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package restxmlwithnamespace 4 5import ( 6 "context" 7 "github.com/aws/aws-sdk-go-v2/aws" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/retry" 10 awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http" 11 smithy "github.com/aws/smithy-go" 12 "github.com/aws/smithy-go/logging" 13 "github.com/aws/smithy-go/middleware" 14 smithyhttp "github.com/aws/smithy-go/transport/http" 15 "net/http" 16) 17 18const ServiceID = "Rest Xml Protocol Namespace" 19const ServiceAPIVersion = "2019-12-16" 20 21// Client provides the API client to make operations call for the API. 22type Client struct { 23 options Options 24} 25 26// New returns an initialized Client based on the functional options. Provide 27// additional functional options to further configure the behavior of the client, 28// such as changing the client's endpoint or adding custom middleware behavior. 29func New(options Options, optFns ...func(*Options)) *Client { 30 options = options.Copy() 31 32 resolveDefaultLogger(&options) 33 34 resolveRetryer(&options) 35 36 resolveHTTPClient(&options) 37 38 resolveDefaultEndpointConfiguration(&options) 39 40 for _, fn := range optFns { 41 fn(&options) 42 } 43 44 client := &Client{ 45 options: options, 46 } 47 48 return client 49} 50 51type Options struct { 52 // Set of options to modify how an operation is invoked. These apply to all 53 // operations invoked for this client. Use functional options on operation call to 54 // modify this list for per operation behavior. 55 APIOptions []func(*middleware.Stack) error 56 57 // Configures the events that will be sent to the configured logger. 58 ClientLogMode aws.ClientLogMode 59 60 // The endpoint options to be used when attempting to resolve an endpoint. 61 EndpointOptions EndpointResolverOptions 62 63 // The service endpoint resolver. 64 EndpointResolver EndpointResolver 65 66 // The logger writer interface to write logging messages to. 67 Logger logging.Logger 68 69 // The region to send requests to. (Required) 70 Region string 71 72 // Retryer guides how HTTP requests should be retried in case of recoverable 73 // failures. When nil the API client will use a default retryer. 74 Retryer aws.Retryer 75 76 // The HTTP client to invoke API calls with. Defaults to client's default HTTP 77 // implementation if nil. 78 HTTPClient HTTPClient 79} 80 81// WithAPIOptions returns a functional option for setting the Client's APIOptions 82// option. 83func WithAPIOptions(optFns ...func(*middleware.Stack) error) func(*Options) { 84 return func(o *Options) { 85 o.APIOptions = append(o.APIOptions, optFns...) 86 } 87} 88 89// WithEndpointResolver returns a functional option for setting the Client's 90// EndpointResolver option. 91func WithEndpointResolver(v EndpointResolver) func(*Options) { 92 return func(o *Options) { 93 o.EndpointResolver = v 94 } 95} 96 97type HTTPClient interface { 98 Do(*http.Request) (*http.Response, error) 99} 100 101// Copy creates a clone where the APIOptions list is deep copied. 102func (o Options) Copy() Options { 103 to := o 104 to.APIOptions = make([]func(*middleware.Stack) error, len(o.APIOptions)) 105 copy(to.APIOptions, o.APIOptions) 106 return to 107} 108func (c *Client) invokeOperation(ctx context.Context, opID string, params interface{}, optFns []func(*Options), stackFns ...func(*middleware.Stack, Options) error) (result interface{}, metadata middleware.Metadata, err error) { 109 ctx = middleware.ClearStackValues(ctx) 110 stack := middleware.NewStack(opID, smithyhttp.NewStackRequest) 111 options := c.options.Copy() 112 for _, fn := range optFns { 113 fn(&options) 114 } 115 116 for _, fn := range stackFns { 117 if err := fn(stack, options); err != nil { 118 return nil, metadata, err 119 } 120 } 121 122 for _, fn := range options.APIOptions { 123 if err := fn(stack); err != nil { 124 return nil, metadata, err 125 } 126 } 127 128 handler := middleware.DecorateHandler(smithyhttp.NewClientHandler(options.HTTPClient), stack) 129 result, metadata, err = handler.Handle(ctx, params) 130 if err != nil { 131 err = &smithy.OperationError{ 132 ServiceID: ServiceID, 133 OperationName: opID, 134 Err: err, 135 } 136 } 137 return result, metadata, err 138} 139 140func resolveDefaultLogger(o *Options) { 141 if o.Logger != nil { 142 return 143 } 144 o.Logger = logging.Nop{} 145} 146 147func addSetLoggerMiddleware(stack *middleware.Stack, o Options) error { 148 return middleware.AddSetLoggerMiddleware(stack, o.Logger) 149} 150 151// NewFromConfig returns a new client from the provided config. 152func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client { 153 opts := Options{ 154 Region: cfg.Region, 155 HTTPClient: cfg.HTTPClient, 156 APIOptions: cfg.APIOptions, 157 Logger: cfg.Logger, 158 ClientLogMode: cfg.ClientLogMode, 159 } 160 resolveAWSRetryerProvider(cfg, &opts) 161 resolveAWSEndpointResolver(cfg, &opts) 162 return New(opts, optFns...) 163} 164 165func resolveHTTPClient(o *Options) { 166 if o.HTTPClient != nil { 167 return 168 } 169 o.HTTPClient = awshttp.NewBuildableClient() 170} 171 172func resolveRetryer(o *Options) { 173 if o.Retryer != nil { 174 return 175 } 176 o.Retryer = retry.NewStandard() 177} 178 179func resolveAWSRetryerProvider(cfg aws.Config, o *Options) { 180 if cfg.Retryer == nil { 181 return 182 } 183 o.Retryer = cfg.Retryer() 184} 185 186func resolveAWSEndpointResolver(cfg aws.Config, o *Options) { 187 if cfg.EndpointResolver == nil { 188 return 189 } 190 o.EndpointResolver = withEndpointResolver(cfg.EndpointResolver, NewDefaultEndpointResolver()) 191} 192 193func addClientUserAgent(stack *middleware.Stack) error { 194 return awsmiddleware.AddRequestUserAgentMiddleware(stack) 195} 196 197func addRetryMiddlewares(stack *middleware.Stack, o Options) error { 198 mo := retry.AddRetryMiddlewaresOptions{ 199 Retryer: o.Retryer, 200 LogRetryAttempts: o.ClientLogMode.IsRetries(), 201 } 202 return retry.AddRetryMiddlewares(stack, mo) 203} 204 205func addRequestIDRetrieverMiddleware(stack *middleware.Stack) error { 206 return awsmiddleware.AddRequestIDRetrieverMiddleware(stack) 207} 208 209func addResponseErrorMiddleware(stack *middleware.Stack) error { 210 return awshttp.AddResponseErrorMiddleware(stack) 211} 212 213func addRequestResponseLogging(stack *middleware.Stack, o Options) error { 214 return stack.Deserialize.Add(&smithyhttp.RequestResponseLogger{ 215 LogRequest: o.ClientLogMode.IsRequest(), 216 LogRequestWithBody: o.ClientLogMode.IsRequestWithBody(), 217 LogResponse: o.ClientLogMode.IsResponse(), 218 LogResponseWithBody: o.ClientLogMode.IsResponseWithBody(), 219 }, middleware.After) 220} 221