Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorLogEncoder(getLogger func(context.Context) *zap.Logger, ee kithttp.ErrorEncoder) kithttp.ErrorEncoder
- func ForwardHeadersByPrefix(p string, from http.Header, to http.Header)
- func Log(reducedLoggingResponseCodes []int) kithttp.ServerFinalizerFunc
- func Welcome(delegate http.Handler) http.Handler
- type CodedError
- type Options
- type Request
- type T
- type XmidtResponse
Constants ¶
const ( ContextKeyRequestArrivalTime contextKey = iota ContextKeyRequestTID )
Keys to important context values on incoming requests to TR1D1UM
Variables ¶
var ErrTr1d1umInternal = errors.New("oops! Something unexpected went wrong in this service")
ErrTr1d1umInternal should be the error shown to external API consumers in Internal Server error cases
Functions ¶
func ErrorLogEncoder ¶
func ErrorLogEncoder(getLogger func(context.Context) *zap.Logger, ee kithttp.ErrorEncoder) kithttp.ErrorEncoder
ErrorLogEncoder decorates the errorEncoder in such a way that errors are logged with their corresponding unique request identifier
func ForwardHeadersByPrefix ¶
ForwardHeadersByPrefix copies headers h where the source and target are 'from' and 'to' respectively such that key(h) has p as prefix
func Log ¶
func Log(reducedLoggingResponseCodes []int) kithttp.ServerFinalizerFunc
Log is used by the different Tr1d1um services to keep track of incoming requests and their corresponding responses
Types ¶
type CodedError ¶
CodedError describes the behavior of an error that additionally has an HTTP status code used for TR1D1UM business logic
func NewBadRequestError ¶
func NewBadRequestError(e error) CodedError
NewBadRequestError is the constructor for an error returned for bad HTTP requests to tr1d1um
func NewCodedError ¶
func NewCodedError(e error, code int) CodedError
NewCodedError upgrades an Error to a CodedError e must not be non-nil to avoid panics
type Options ¶
type Options struct { //RequestTimeout is the deadline duration for the HTTP transaction to be completed RequestTimeout time.Duration //Do is the core responsible to perform the actual HTTP request Do func(*http.Request) (*http.Response, error) }
Options include parameters needed to configure the transactor
type Request ¶
type Request struct { Address string `json:"address,omitempty"` Path string `json:"path,omitempty"` Query string `json:"query,omitempty"` Method string `json:"method,omitempty"` }
func (*Request) MarshalJSON ¶
type T ¶
type T interface {
Transact(*http.Request) (*XmidtResponse, error)
}
T performs a typical HTTP request but enforces some logic onto the HTTP transaction such as context-based timeout and header filtering this is a common utility for the stat and config tr1d1um services
type XmidtResponse ¶
type XmidtResponse struct { //Code is the HTTP Status code received from the transaction Code int //ForwardedHeaders contains all the headers tr1d1um keeps from the transaction ForwardedHeaders http.Header //Body represents the full data off the XMiDT http.Response body Body []byte }
XmidtResponse represents the data that a tr1d1um transactor keeps from an HTTP request to the XMiDT API