transaction

package
v0.10.44 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKeyRequestArrivalTime contextKey = iota
	ContextKeyRequestTID
)

Keys to important context values on incoming requests to TR1D1UM

Variables

View Source
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

func ForwardHeadersByPrefix(p string, from http.Header, to http.Header)

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

func Welcome

func Welcome(delegate http.Handler) http.Handler

Welcome is an Alice-style constructor that defines necessary request context values assumed to exist by the delegate. These values should be those expected to be used both in and outside the gokit server flow

Types

type CodedError

type CodedError interface {
	error
	StatusCode() int
}

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

func (re *Request) MarshalJSON() ([]byte, error)

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

func New

func New(o *Options) T

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL