github.com/xmidt-org/webpa-common@v1.11.9/xhttp/fanout/result.go (about)

     1  package fanout
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/xmidt-org/webpa-common/tracing"
     7  )
     8  
     9  // Result is the result from a single fanout HTTP transaction
    10  type Result struct {
    11  	// StatusCode is the HTTP status code from the response, or an inferred status code
    12  	// if the transaction returned an error.  This value will be populated even if Response is nil.
    13  	StatusCode int
    14  
    15  	// Request is the HTTP request sent to the fanout endpoint.  This will always be non-nil.
    16  	Request *http.Request
    17  
    18  	// Response is the HTTP response returned by the fanout HTTP transaction.  If set, Err will be nil.
    19  	Response *http.Response
    20  
    21  	// Err is the error returned by the fanout HTTP transaction.  If set, Response will be nil.
    22  	Err error
    23  
    24  	// ContentType is the MIME type of the Body
    25  	ContentType string
    26  
    27  	// Body is the HTTP response entity returned by the fanout HTTP transaction.  This can be nil or empty.
    28  	Body []byte
    29  
    30  	// Span represents the execution block that handled this fanout transaction
    31  	Span tracing.Span
    32  }
    33  
    34  // ShouldTerminateFunc is a predicate for determining if a fanout should terminate early given the results of
    35  // a single HTTP transaction.
    36  type ShouldTerminateFunc func(Result) bool
    37  
    38  // DefaultShouldTerminate is the default strategy for determining if an HTTP transaction should result
    39  // in early termination of the fanout.  This function returns true if the status code is a non-error HTTP status.
    40  func DefaultShouldTerminate(result Result) bool {
    41  	return result.StatusCode < 400
    42  }