Documentation ¶
Index ¶
- Constants
- func AsyncFetch[T any](ctx context.Context, opCtx ObjectFetchSpec[T], c *HttpTransport, ...)
- func Count[T any](ctx context.Context, opCtx ObjectListFetchSpec[T], c *HttpTransport) (int64, error)
- func CreateObject[T any](ctx context.Context, opCtx ObjectUpsertSpec[T], c *HttpTransport) (T, error)
- func DefaultTLSConfig() *tls.Config
- func DeleteObject[T any](ctx context.Context, opCtx ObjectFetchSpec[T], c *HttpTransport) error
- func ExchangeObject[TIn, TOut any](ctx context.Context, opCtx ObjectExchangeSpec[TIn, TOut], verb string, ...) (TOut, error)
- func Exists[T any](ctx context.Context, opCtx ObjectFetchSpec[T], c *HttpTransport) (bool, error)
- func FetchAll[T any](ctx context.Context, opCtx ObjectListFetchSpec[T], c *HttpTransport) ([]T, error)
- func FetchAllWithExists[T any](ctx context.Context, opCtx ObjectListFetchSpec[T], c *HttpTransport) ([]T, bool, error)
- func GetObject[T any](ctx context.Context, opCtx ObjectFetchSpec[T], c *HttpTransport) (T, bool, error)
- func ReadResponseBody(r *http.Response) ([]byte, error)
- func UpdateObject[T any](ctx context.Context, opCtx ObjectUpsertSpec[T], c *HttpTransport) (T, error)
- type AsyncFetchResult
- type Authorizer
- type CallFunc
- type ChainedMiddlewareFunc
- type CommonFetchSpec
- type CommonFetchSpecBuilder
- func (b *CommonFetchSpecBuilder) Build() CommonFetchSpec
- func (b *CommonFetchSpecBuilder) BuildQuery() url.Values
- func (b *CommonFetchSpecBuilder) WithAppContext(p string) *CommonFetchSpecBuilder
- func (b *CommonFetchSpecBuilder) WithIgnoreResponse(p bool) *CommonFetchSpecBuilder
- func (b *CommonFetchSpecBuilder) WithMergedQuery(p url.Values) *CommonFetchSpecBuilder
- func (b *CommonFetchSpecBuilder) WithPagination(p PaginationType) *CommonFetchSpecBuilder
- func (b *CommonFetchSpecBuilder) WithQuery(p url.Values) *CommonFetchSpecBuilder
- func (b *CommonFetchSpecBuilder) WithResource(p string, params ...interface{}) *CommonFetchSpecBuilder
- func (b *CommonFetchSpecBuilder) WithReturn404AsNil(p bool) *CommonFetchSpecBuilder
- type ContextSupplier
- type ExchangeListener
- type FetchSpec
- type HTTPClientParams
- type HttpExecutor
- type HttpResourceFetcher
- type HttpTransport
- func (c *HttpTransport) Count(ctx context.Context, opCtx CommonFetchSpec) (int64, error)
- func (c *HttpTransport) DelayBeforeCall() time.Duration
- func (c *HttpTransport) Delete(ctx context.Context, res string) (*WrappedResponse, error)
- func (c *HttpTransport) Fetch(ctx context.Context, res string) (*WrappedResponse, error)
- func (c *HttpTransport) Post(ctx context.Context, res string, body interface{}) (*WrappedResponse, error)
- func (c *HttpTransport) Put(ctx context.Context, res string, body interface{}) (*WrappedResponse, error)
- func (c *HttpTransport) Send(ctx context.Context, meth string, res string, body interface{}) (*WrappedResponse, error)
- type MiddlewareFunc
- type MiddlewareFuncPipeline
- type ObjectExchangeSpec
- type ObjectExchangeSpecBuilder
- type ObjectFetchSpec
- type ObjectFetchSpecBuilder
- type ObjectListFetchSpec
- type ObjectListFetchSpecBuilder
- type ObjectUpsertSpec
- type ObjectUpsertSpecBuilder
- type PaginationType
- type ReceivedFeederResponse
- type ResponseParserFunc
- type Supplier
- type TLSCertChainPin
- type TLSPinner
- type TokenFeederResponse
- type VaultAuthorizer
- type VaultToken
- type VaultTokenFeederResponse
- type WrappedRequest
- type WrappedResponse
- func BackOffOnDeveloperOverQPSFunc(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)
- func BreakOnDeveloperOverRateFunc(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)
- func EnsureBodyWasRead(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)
- func ErrorOn404Func(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)
- func ExecuteFunction(ctx context.Context, c *HttpTransport) (*WrappedResponse, error)
- func RetryOn400Func(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)
- func ThrottleFunc(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)
- func UnmarshalServerError(ctx context.Context, c *HttpTransport, next MiddlewareFunc) (*WrappedResponse, error)
Constants ¶
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 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 ¶
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 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 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 (b *CommonFetchSpecBuilder) Build() CommonFetchSpec
func (*CommonFetchSpecBuilder) BuildQuery ¶
func (b *CommonFetchSpecBuilder) BuildQuery() url.Values
func (*CommonFetchSpecBuilder) WithAppContext ¶
func (b *CommonFetchSpecBuilder) WithAppContext(p string) *CommonFetchSpecBuilder
func (*CommonFetchSpecBuilder) WithIgnoreResponse ¶
func (b *CommonFetchSpecBuilder) WithIgnoreResponse(p bool) *CommonFetchSpecBuilder
func (*CommonFetchSpecBuilder) WithMergedQuery ¶
func (b *CommonFetchSpecBuilder) WithMergedQuery(p url.Values) *CommonFetchSpecBuilder
func (*CommonFetchSpecBuilder) WithPagination ¶
func (b *CommonFetchSpecBuilder) WithPagination(p PaginationType) *CommonFetchSpecBuilder
func (*CommonFetchSpecBuilder) WithQuery ¶
func (b *CommonFetchSpecBuilder) WithQuery(p url.Values) *CommonFetchSpecBuilder
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 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 ¶
DestResource Resource that need to be called on the server. This method will return the resource and will append the query string, if specified
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 HttpResourceFetcher ¶
type HttpResourceFetcher struct {
// contains filtered or unexported fields
}
func (*HttpResourceFetcher) Close ¶
func (h *HttpResourceFetcher) Close()
func (*HttpResourceFetcher) HeaderAuthorization ¶
func (*HttpResourceFetcher) QueryStringAuthorization ¶
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 (b *ObjectListFetchSpecBuilder[T]) Build() ObjectListFetchSpec[T]
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
}
type ResponseParserFunc ¶
ResponseParserFunc Function that parses responses returned by JSON.
type TLSCertChainPin ¶
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 ¶
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 (VaultAuthorizer) QueryStringAuthorization ¶
type VaultToken ¶
type VaultToken string
type VaultTokenFeederResponse ¶
type VaultTokenFeederResponse struct {
Data TokenFeederResponse `json:"data"`
}
type WrappedRequest ¶
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