From 9677a9f71777d75f3def0b0cb238050a30ec6a67 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 29 Jul 2015 01:26:10 -0800 Subject: Fixes mm-1355 adds rate limiting apis --- .../github.com/awslabs/aws-sdk-go/aws/service.go | 142 --------------------- 1 file changed, 142 deletions(-) delete mode 100644 Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws/service.go (limited to 'Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws/service.go') diff --git a/Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws/service.go b/Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws/service.go deleted file mode 100644 index 95d590b91..000000000 --- a/Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws/service.go +++ /dev/null @@ -1,142 +0,0 @@ -package aws - -import ( - "fmt" - "math" - "net/http" - "net/http/httputil" - "regexp" - "time" - - "github.com/awslabs/aws-sdk-go/internal/endpoints" -) - -type Service struct { - Config *Config - Handlers Handlers - ManualSend bool - ServiceName string - APIVersion string - Endpoint string - JSONVersion string - TargetPrefix string - RetryRules func(*Request) time.Duration - ShouldRetry func(*Request) bool - DefaultMaxRetries uint -} - -var schemeRE = regexp.MustCompile("^([^:]+)://") - -func NewService(config *Config) *Service { - svc := &Service{Config: config} - svc.Initialize() - return svc -} - -func (s *Service) Initialize() { - if s.Config == nil { - s.Config = &Config{} - } - if s.Config.HTTPClient == nil { - s.Config.HTTPClient = http.DefaultClient - } - - if s.RetryRules == nil { - s.RetryRules = retryRules - } - - if s.ShouldRetry == nil { - s.ShouldRetry = shouldRetry - } - - s.DefaultMaxRetries = 3 - s.Handlers.Build.PushBack(UserAgentHandler) - s.Handlers.Sign.PushBack(BuildContentLength) - s.Handlers.Send.PushBack(SendHandler) - s.Handlers.AfterRetry.PushBack(AfterRetryHandler) - s.Handlers.ValidateResponse.PushBack(ValidateResponseHandler) - s.AddDebugHandlers() - s.buildEndpoint() - - if !s.Config.DisableParamValidation { - s.Handlers.Validate.PushBack(ValidateParameters) - } -} - -func (s *Service) buildEndpoint() { - if s.Config.Endpoint != "" { - s.Endpoint = s.Config.Endpoint - } else { - s.Endpoint = endpoints.EndpointForRegion(s.ServiceName, s.Config.Region) - } - - if !schemeRE.MatchString(s.Endpoint) { - scheme := "https" - if s.Config.DisableSSL { - scheme = "http" - } - s.Endpoint = scheme + "://" + s.Endpoint - } -} - -func (s *Service) AddDebugHandlers() { - out := s.Config.Logger - if s.Config.LogLevel == 0 { - return - } - - s.Handlers.Sign.PushBack(func(r *Request) { - dumpedBody, _ := httputil.DumpRequest(r.HTTPRequest, true) - - fmt.Fprintf(out, "=> [%s] %s.%s(%+v)\n", r.Time, - r.Service.ServiceName, r.Operation.Name, r.Params) - fmt.Fprintf(out, "---[ REQUEST PRE-SIGN ]------------------------------\n") - fmt.Fprintf(out, "%s\n", string(dumpedBody)) - fmt.Fprintf(out, "-----------------------------------------------------\n") - }) - s.Handlers.Send.PushFront(func(r *Request) { - dumpedBody, _ := httputil.DumpRequest(r.HTTPRequest, true) - - fmt.Fprintf(out, "---[ REQUEST POST-SIGN ]-----------------------------\n") - fmt.Fprintf(out, "%s\n", string(dumpedBody)) - fmt.Fprintf(out, "-----------------------------------------------------\n") - }) - s.Handlers.Send.PushBack(func(r *Request) { - fmt.Fprintf(out, "---[ RESPONSE ]--------------------------------------\n") - if r.HTTPResponse != nil { - dumpedBody, _ := httputil.DumpResponse(r.HTTPResponse, true) - fmt.Fprintf(out, "%s\n", string(dumpedBody)) - } else if r.Error != nil { - fmt.Fprintf(out, "%s\n", r.Error) - } - fmt.Fprintf(out, "-----------------------------------------------------\n") - }) -} - -func (s *Service) MaxRetries() uint { - if s.Config.MaxRetries < 0 { - return s.DefaultMaxRetries - } else { - return uint(s.Config.MaxRetries) - } -} - -func retryRules(r *Request) time.Duration { - delay := time.Duration(math.Pow(2, float64(r.RetryCount))) * 30 - return delay * time.Millisecond -} - -func shouldRetry(r *Request) bool { - if err := Error(r.Error); err != nil { - if err.StatusCode >= 500 { - return true - } - - switch err.Code { - case "ExpiredTokenException": - case "ProvisionedThroughputExceededException", "Throttling": - return true - } - } - return false -} -- cgit v1.2.3-1-g7c22