transport

package
v0.0.0-...-8a9b062 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SendErrorOn404 = ".send.error.on.404"
	RetryOn400     = ".retry.on.400"
	LeafExecutor   = ".leaf.executor"
)

Variables

This section is empty.

Functions

func AsyncFetch

func AsyncFetch[T any](ctx context.Context, opCtx ObjectFetchSpec[T], c *HttpTransport, comm chan AsyncFetchResult[T])

AsyncFetch Perform a fetch asynchronously, returning the response in the provided channel.

func Count

func Count[T any](ctx context.Context, opCtx ObjectListFetchSpec[T], c *HttpTransport) (int64, error)

Count the number of objects that match the specified criteria

func CreateObject

func CreateObject[T any](ctx context.Context, opCtx ObjectUpsertSpec[T], c *HttpTransport) (T, error)

func DefaultTLSConfig

func DefaultTLSConfig() *tls.Config

func DeleteObject

func DeleteObject[T any](ctx context.Context, opCtx ObjectFetchSpec[T], c *HttpTransport) error

func ExchangeObject

func ExchangeObject[TIn, TOut any](ctx context.Context, opCtx ObjectExchangeSpec[TIn, TOut], verb string, c *HttpTransport) (TOut, error)

ExchangeObject exchange an input object for the output one.

func Exists

func Exists[T any](ctx context.Context, opCtx ObjectFetchSpec[T], c *HttpTransport) (bool, error)

func FetchAll

func FetchAll[T any](ctx context.Context, opCtx ObjectListFetchSpec[T], c *HttpTransport) ([]T, error)

func FetchAllWithExists

func FetchAllWithExists[T any](ctx context.Context, opCtx ObjectListFetchSpec[T], c *HttpTransport) ([]T, bool, error)

FetchAllWithExists Fetch all Mashery objects, including the handling for the pagination

func GetObject

func GetObject[T any](ctx context.Context, opCtx ObjectFetchSpec[T], c *HttpTransport) (T, bool, error)

func ReadResponseBody

func ReadResponseBody(r *http.Response) ([]byte, error)

ReadResponseBody Reads the response body of the response

func UpdateObject

func UpdateObject[T any](ctx context.Context, opCtx ObjectUpsertSpec[T], c *HttpTransport) (T, error)

Types

type AsyncFetchResult

type AsyncFetchResult[T any] struct {
	Data T
	Err  error
}

type Authorizer

type Authorizer interface {
	HeaderAuthorization(ctx context.Context) (map[string]string, error)
	QueryStringAuthorization(ctx context.Context) (map[string]string, error)
	Close()
}

func NewBearerAuthorizer

func NewBearerAuthorizer(token string) Authorizer

NewBearerAuthorizer Bearer token authorization

func NewVaultAuthorizer

func NewVaultAuthorizer(token VaultToken) Authorizer

NewVaultAuthorizer Create HashiCorp vault authorizer

func NewVaultTokenResourceAuthorizer

func NewVaultTokenResourceAuthorizer(url string, token VaultToken) Authorizer

type CallFunc

type CallFunc func(ctx context.Context) (*WrappedResponse, error)

type ChainedMiddlewareFunc

type ChainedMiddlewareFunc func(ctx context.Context, transport *HttpTransport, middlewareFunc MiddlewareFunc) (*WrappedResponse, error)

ChainedMiddlewareFunc is a middleware function

type CommonFetchSpec

type CommonFetchSpec struct {
	Pagination PaginationType
	Resource   string
	Query      url.Values
	AppContext string
	// TODO: This needs to be renamed into Return404AsError
	Return404AsNil bool
	IgnoreResponse bool

	FetchMiddleware []ChainedMiddlewareFunc
}

func (*CommonFetchSpec) DestResource

func (ctx *CommonFetchSpec) DestResource() string

DestResource Resource that need to be called on the server. This method will return the resource and will append the query string, if specified

func (*CommonFetchSpec) FetchFunc

func (cfs *CommonFetchSpec) FetchFunc() func(ctx context.Context, c *HttpTransport) (*WrappedResponse, error)

func (*CommonFetchSpec) ToBuilder

func (cfs *CommonFetchSpec) ToBuilder() CommonFetchSpecBuilder

type CommonFetchSpecBuilder

type CommonFetchSpecBuilder struct {
	Pagination     PaginationType
	Resource       string
	Query          url.Values
	AppContext     string
	Return404AsNil bool
	IgnoreResponse bool
}

func (*CommonFetchSpecBuilder) Build

func (*CommonFetchSpecBuilder) BuildQuery

func (b *CommonFetchSpecBuilder) BuildQuery() url.Values

func (*CommonFetchSpecBuilder) WithAppContext

func (*CommonFetchSpecBuilder) WithIgnoreResponse

func (b *CommonFetchSpecBuilder) WithIgnoreResponse(p bool) *CommonFetchSpecBuilder

func (*CommonFetchSpecBuilder) WithMergedQuery

func (*CommonFetchSpecBuilder) WithPagination

func (*CommonFetchSpecBuilder) WithQuery

func (*CommonFetchSpecBuilder) WithResource

func (b *CommonFetchSpecBuilder) WithResource(p string, params ...interface{}) *CommonFetchSpecBuilder

func (*CommonFetchSpecBuilder) WithReturn404AsNil

func (b *CommonFetchSpecBuilder) WithReturn404AsNil(p bool) *CommonFetchSpecBuilder

type ContextSupplier

type ContextSupplier[T any] func(ctx context.Context) T

type ExchangeListener

type ExchangeListener func(ctx context.Context, req *WrappedRequest, res *WrappedResponse, err error)

ExchangeListener receive a notification of a raw exchange: what was actually sent to Mashery, and which response was received

type FetchSpec

type FetchSpec struct {
	// Left temporarily: this type has to disappear
	Pagination     PaginationType
	Resource       string
	Query          url.Values
	AppContext     string
	ResponseParser ResponseParserFunc
	Return404AsNil bool
}

FetchSpec Operation context

func (*FetchSpec) DestResource

func (ctx *FetchSpec) DestResource() string

DestResource Resource that need to be called on the server. This method will return the resource and will append the query string, if specified

func (*FetchSpec) WithQuery

func (ctx *FetchSpec) WithQuery(qs url.Values) FetchSpec

WithQuery Append extra query parameters to the parent context

type HTTPClientParams

type HTTPClientParams struct {
	TLSConfig               *tls.Config
	TLSConfigDelegateSystem bool
	Timeout                 time.Duration

	ProxyServer          *url.URL
	ProxyAuthType        string
	ProxyAuthCredentials string

	ExchangeListener ExchangeListener

	ExplicitHttpExecutor HttpExecutor
}

func (*HTTPClientParams) CreateHttpExecutor

func (p *HTTPClientParams) CreateHttpExecutor() HttpExecutor

type HttpExecutor

type HttpExecutor interface {
	Do(r *http.Request) (*http.Response, error)
	CloseIdleConnections()
}

type HttpResourceFetcher

type HttpResourceFetcher struct {
	// contains filtered or unexported fields
}

func (*HttpResourceFetcher) Close

func (h *HttpResourceFetcher) Close()

func (*HttpResourceFetcher) HeaderAuthorization

func (h *HttpResourceFetcher) HeaderAuthorization(ctx context.Context) (map[string]string, error)

func (*HttpResourceFetcher) QueryStringAuthorization

func (h *HttpResourceFetcher) QueryStringAuthorization(_ context.Context) (map[string]string, error)

type HttpTransport

type HttpTransport struct {
	MashEndpoint  string
	Authorizer    Authorizer
	AvgNetLatency time.Duration
	HttpExecutor  HttpExecutor

	PlannedSecond  int64
	AllocatedCalls int64
	MaxQPS         int64

	Mutex *sync.Mutex

	ExchangeListener ExchangeListener
	Pipeline         MiddlewareFunc
}

func (*HttpTransport) Count

func (c *HttpTransport) Count(ctx context.Context, opCtx CommonFetchSpec) (int64, error)

Count the number of objects that match the specified criteria

func (*HttpTransport) DelayBeforeCall

func (c *HttpTransport) DelayBeforeCall() time.Duration

func (*HttpTransport) Delete

func (c *HttpTransport) Delete(ctx context.Context, res string) (*WrappedResponse, error)

func (*HttpTransport) Fetch

func (c *HttpTransport) Fetch(ctx context.Context, res string) (*WrappedResponse, error)

func (*HttpTransport) Post

func (c *HttpTransport) Post(ctx context.Context, res string, body interface{}) (*WrappedResponse, error)

func (*HttpTransport) Put

func (c *HttpTransport) Put(ctx context.Context, res string, body interface{}) (*WrappedResponse, error)

func (*HttpTransport) Send

func (c *HttpTransport) Send(ctx context.Context, meth string, res string, body interface{}) (*WrappedResponse, error)

type MiddlewareFunc

type MiddlewareFunc func(ctx context.Context, transport *HttpTransport) (*WrappedResponse, error)

func BuildPipeline

func BuildPipeline(mf MiddlewareFunc, funcs []ChainedMiddlewareFunc) MiddlewareFunc

BuildPipeline builds a call execution pipeline from the supplied chained middleware functions.

type MiddlewareFuncPipeline

type MiddlewareFuncPipeline struct {
	// contains filtered or unexported fields
}

type ObjectExchangeSpec

type ObjectExchangeSpec[TIn, TOut any] struct {
	ObjectFetchSpec[TOut]
	Body TIn
}

type ObjectExchangeSpecBuilder

type ObjectExchangeSpecBuilder[TIn, TOut any] struct {
	ObjectFetchSpecBuilder[TOut]
	Body TIn
}

func (*ObjectExchangeSpecBuilder[TIn, TOut]) Build

func (b *ObjectExchangeSpecBuilder[TIn, TOut]) Build() ObjectExchangeSpec[TIn, TOut]

func (*ObjectExchangeSpecBuilder[TIn, TOut]) WithBody

func (b *ObjectExchangeSpecBuilder[TIn, TOut]) WithBody(p TIn) *ObjectExchangeSpecBuilder[TIn, TOut]

type ObjectFetchSpec

type ObjectFetchSpec[T any] struct {
	CommonFetchSpec
	ValueFactory Supplier[T]
}

type ObjectFetchSpecBuilder

type ObjectFetchSpecBuilder[T any] struct {
	CommonFetchSpecBuilder
	ValueFactory Supplier[T]
}

func (*ObjectFetchSpecBuilder[T]) Build

func (b *ObjectFetchSpecBuilder[T]) Build() ObjectFetchSpec[T]

func (*ObjectFetchSpecBuilder[T]) WithValueFactory

func (b *ObjectFetchSpecBuilder[T]) WithValueFactory(p Supplier[T]) *ObjectFetchSpecBuilder[T]

type ObjectListFetchSpec

type ObjectListFetchSpec[T any] struct {
	CommonFetchSpec
	ValueFactory Supplier[[]T]
}

func (ObjectListFetchSpec[T]) AsObjectFetchSpec

func (olfs ObjectListFetchSpec[T]) AsObjectFetchSpec() ObjectFetchSpec[[]T]

func (ObjectListFetchSpec[T]) ToBuilder

func (olfs ObjectListFetchSpec[T]) ToBuilder() ObjectListFetchSpecBuilder[T]

type ObjectListFetchSpecBuilder

type ObjectListFetchSpecBuilder[T any] struct {
	CommonFetchSpecBuilder
	ValueFactory Supplier[[]T]
}

func (*ObjectListFetchSpecBuilder[T]) Build

func (*ObjectListFetchSpecBuilder[T]) WithValueFactory

func (b *ObjectListFetchSpecBuilder[T]) WithValueFactory(p Supplier[[]T]) *ObjectListFetchSpecBuilder[T]

type ObjectUpsertSpec

type ObjectUpsertSpec[T any] struct {
	ObjectFetchSpec[T]
	Upsert T
}

type ObjectUpsertSpecBuilder

type ObjectUpsertSpecBuilder[T any] struct {
	ObjectFetchSpecBuilder[T]
	Upsert T
}

func (*ObjectUpsertSpecBuilder[T]) Build

func (b *ObjectUpsertSpecBuilder[T]) Build() ObjectUpsertSpec[T]

func (*ObjectUpsertSpecBuilder[T]) WithUpsert

func (b *ObjectUpsertSpecBuilder[T]) WithUpsert(p T) *ObjectUpsertSpecBuilder[T]

type PaginationType

type PaginationType int
const (
	PerPage PaginationType = iota
	PerItem
	NotRequired
)

type ReceivedFeederResponse

type ReceivedFeederResponse struct {
	// contains filtered or unexported fields
}

func (*ReceivedFeederResponse) IsExpired

func (rfr *ReceivedFeederResponse) IsExpired(debounce time.Duration) bool

type ResponseParserFunc

type ResponseParserFunc func(data []byte) (interface{}, int, error)

ResponseParserFunc Function that parses responses returned by JSON.

type Supplier

type Supplier[T any] func() T

type TLSCertChainPin

type TLSCertChainPin struct {
	CommonName   string
	SerialNumber []byte
	Fingerprint  []byte
}

func (*TLSCertChainPin) FingerprintFrom

func (pin *TLSCertChainPin) FingerprintFrom(str string) error

func (*TLSCertChainPin) IsEmpty

func (pin *TLSCertChainPin) IsEmpty() bool

func (TLSCertChainPin) PinnedSerial

func (pin TLSCertChainPin) PinnedSerial() *big.Int

func (*TLSCertChainPin) SerialNumberFromHex

func (pin *TLSCertChainPin) SerialNumberFromHex(str string) error

type TLSPinner

type TLSPinner struct {
	TLSCertChainPins []TLSCertChainPin
}

func (*TLSPinner) Add

func (pinner *TLSPinner) Add(pin TLSCertChainPin) *TLSPinner

func (*TLSPinner) CreateTLSConfig

func (tlp *TLSPinner) CreateTLSConfig() *tls.Config

type TokenFeederResponse

type TokenFeederResponse struct {
	// Token contains token that can be used for authentication and authorization
	Token string `json:"access_token"`
	// Expiry contains the expiry time of this token.
	Expiry string `json:"expiry"`
	// ExpiryEpoch contains epoch time the token will expire and will no longer be usable
	ExpiryEpoch int64 `json:"expiry_epoch"`
}

type VaultAuthorizer

type VaultAuthorizer struct {
	Authorizer
	// contains filtered or unexported fields
}

func (VaultAuthorizer) Close

func (va VaultAuthorizer) Close()

func (VaultAuthorizer) HeaderAuthorization

func (va VaultAuthorizer) HeaderAuthorization(_ context.Context) (map[string]string, error)

func (VaultAuthorizer) QueryStringAuthorization

func (va VaultAuthorizer) QueryStringAuthorization(_ context.Context) (map[string]string, error)

type VaultToken

type VaultToken string

type VaultTokenFeederResponse

type VaultTokenFeederResponse struct {
	Data TokenFeederResponse `json:"data"`
}

type WrappedRequest

type WrappedRequest struct {
	Request *http.Request
	Body    interface{}
}

type WrappedResponse

type WrappedResponse struct {
	Request    *WrappedRequest
	Response   *http.Response
	StatusCode int
	Header     http.Header
	// contains filtered or unexported fields
}

WrappedResponse Wraps the response so that calling applications can safely read the body multiple times.

func BackOffOnDeveloperOverQPSFunc

func BackOffOnDeveloperOverQPSFunc(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)

func BreakOnDeveloperOverRateFunc

func BreakOnDeveloperOverRateFunc(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)

func EnsureBodyWasRead

func EnsureBodyWasRead(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)

func ErrorOn404Func

func ErrorOn404Func(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)

func ExecuteFunction

func ExecuteFunction(ctx context.Context, c *HttpTransport) (*WrappedResponse, error)

func RetryOn400Func

func RetryOn400Func(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)

func ThrottleFunc

func ThrottleFunc(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)

func UnmarshalServerError

func UnmarshalServerError(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)

func (*WrappedResponse) Body

func (wr *WrappedResponse) Body() ([]byte, error)

func (*WrappedResponse) MustBody

func (wr *WrappedResponse) MustBody() []byte

Jump to

Keyboard shortcuts

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