metadata.go (1616B)
1 package retry 2 3 import ( 4 awsmiddle "github.com/aws/aws-sdk-go-v2/aws/middleware" 5 "github.com/aws/smithy-go/middleware" 6 ) 7 8 // attemptResultsKey is a metadata accessor key to retrieve metadata 9 // for all request attempts. 10 type attemptResultsKey struct { 11 } 12 13 // GetAttemptResults retrieves attempts results from middleware metadata. 14 func GetAttemptResults(metadata middleware.Metadata) (AttemptResults, bool) { 15 m, ok := metadata.Get(attemptResultsKey{}).(AttemptResults) 16 return m, ok 17 } 18 19 // AttemptResults represents struct containing metadata returned by all request attempts. 20 type AttemptResults struct { 21 22 // Results is a slice consisting attempt result from all request attempts. 23 // Results are stored in order request attempt is made. 24 Results []AttemptResult 25 } 26 27 // AttemptResult represents attempt result returned by a single request attempt. 28 type AttemptResult struct { 29 30 // Err is the error if received for the request attempt. 31 Err error 32 33 // Retryable denotes if request may be retried. This states if an 34 // error is considered retryable. 35 Retryable bool 36 37 // Retried indicates if this request was retried. 38 Retried bool 39 40 // ResponseMetadata is any existing metadata passed via the response middlewares. 41 ResponseMetadata middleware.Metadata 42 } 43 44 // addAttemptResults adds attempt results to middleware metadata 45 func addAttemptResults(metadata *middleware.Metadata, v AttemptResults) { 46 metadata.Set(attemptResultsKey{}, v) 47 } 48 49 // GetRawResponse returns raw response recorded for the attempt result 50 func (a AttemptResult) GetRawResponse() interface{} { 51 return awsmiddle.GetRawResponse(a.ResponseMetadata) 52 }