Documentation ¶
Overview ¶
Package maniphttp provides a ReST backed Manipulator.
This is meant to be use to communicate with Bahamut based API servers.
Index ¶
- func BatchCreate(manipulator manipulate.Manipulator, mctx manipulate.Context, ...) (*http.Response, error)
- func ContextOptionAdditionalHeaders(headers http.Header) manipulate.ContextOption
- func ContextOptionOverrideAccept(accept string) manipulate.ContextOption
- func ContextOptionOverrideContentType(encoding string) manipulate.ContextOption
- func DirectSend(manipulator manipulate.Manipulator, mctx manipulate.Context, endpoint string, ...) (*http.Response, error)
- func ExtractClient(manipulator manipulate.Manipulator) *http.Client
- func ExtractCredentials(manipulator manipulate.Manipulator) (string, string)
- func ExtractEncoding(manipulator manipulate.Manipulator) elemental.EncodingType
- func ExtractEndpoint(manipulator manipulate.Manipulator) string
- func ExtractNamespace(manipulator manipulate.Manipulator) string
- func ExtractTLSConfig(manipulator manipulate.Manipulator) *tls.Config
- func ExtractTransport(manipulator manipulate.Manipulator) *http.Transport
- func New(ctx context.Context, url string, options ...Option) (manipulate.Manipulator, error)
- func NewSubscriber(manipulator manipulate.Manipulator, options ...SubscriberOption) manipulate.Subscriber
- func NewSubscriberWithEndpoint(manipulator manipulate.Manipulator, endpoint string, recursive bool) manipulate.Subscriber
- func SetGlobalHeaders(manipulator manipulate.Manipulator, headers http.Header)
- type Option
- func OptionAdditonalHeaders(headers http.Header) Option
- func OptionBackoffCurve(curve []time.Duration) Option
- func OptionCredentials(username, password string) Option
- func OptionDefaultRetryFunc(f manipulate.RetryFunc) Option
- func OptionDisableBuiltInRetry() Option
- func OptionDisableCompression() Option
- func OptionEncoding(enc elemental.EncodingType) Option
- func OptionHTTPClient(client *http.Client) Option
- func OptionHTTPTransport(transport *http.Transport) Option
- func OptionNamespace(ns string) Option
- func OptionSendCredentialsAsCookie(key string) Option
- func OptionSimulateFailures(failureSimulations map[float64]error) Option
- func OptionStrongBackoffCurve(curve []time.Duration) Option
- func OptionTCPUserTimeout(t time.Duration) Option
- func OptionTLSClientCertificates(cert ...tls.Certificate) Option
- func OptionTLSConfig(tlsConfig *tls.Config) Option
- func OptionToken(token string) Option
- func OptionTokenManager(tokenManager manipulate.TokenManager) Option
- type RetryInfo
- type SubscriberOption
- func SubscriberOptionEndpoint(endpoint string) SubscriberOption
- func SubscriberOptionNamespace(namespace string) SubscriberOption
- func SubscriberOptionRecursive(recursive bool) SubscriberOption
- func SubscriberOptionSupportErrorEvents() SubscriberOption
- func SubscriberSendCredentialsAsCookie(key string) SubscriberOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BatchCreate ¶ added in v1.121.1
func BatchCreate(manipulator manipulate.Manipulator, mctx manipulate.Context, objects ...elemental.Identifiable) (*http.Response, error)
BatchCreate is an experimental feature that may eventually be incorporated in the standard interface.
But for now it is not recommended to use it unless you know exactly how this works on the server side. This API is NOT considered as stable and may break at any time.
func ContextOptionAdditionalHeaders ¶ added in v1.130.0
func ContextOptionAdditionalHeaders(headers http.Header) manipulate.ContextOption
ContextOptionAdditionalHeaders is an advanced feature that allows to inject additional HTTP headers in the request. They will be inserted before traditional headers and after global additional headers. This means you cannot use this option to override headers normally inserted by the manipulator, but you can override the global ones.
func ContextOptionOverrideAccept ¶ added in v1.121.1
func ContextOptionOverrideAccept(accept string) manipulate.ContextOption
ContextOptionOverrideAccept is an advanced feature that allows you to override with the actual Accept header value. This should not be used in 99% of the case.
func ContextOptionOverrideContentType ¶ added in v1.121.1
func ContextOptionOverrideContentType(encoding string) manipulate.ContextOption
ContextOptionOverrideContentType is an advanced feature that allows you to override with the actual Content-Type header value. This should not be used in 99% of the case.
func DirectSend ¶ added in v1.60.0
func DirectSend(manipulator manipulate.Manipulator, mctx manipulate.Context, endpoint string, method string, body []byte) (*http.Response, error)
DirectSend allows to send direct bytes using the given manipulator. This is only useful in extremely particular scenario, like fuzzing. Note: the given manipulator must be an HTTP Manipulator or it will panic.
func ExtractClient ¶ added in v1.130.0
func ExtractClient(manipulator manipulate.Manipulator) *http.Client
ExtractClient returns the http.Client used by the given manipulator. This is an advanced feature and the returned client should not be modified.
func ExtractCredentials ¶
func ExtractCredentials(manipulator manipulate.Manipulator) (string, string)
ExtractCredentials extracts the username and password from the given manipulator. Note: the given manipulator must be an HTTP Manipulator or it will return an error.
func ExtractEncoding ¶
func ExtractEncoding(manipulator manipulate.Manipulator) elemental.EncodingType
ExtractEncoding returns the encoding used by the given manipulator. Note: the given manipulator must be an HTTP Manipulator or it will panic.
func ExtractEndpoint ¶
func ExtractEndpoint(manipulator manipulate.Manipulator) string
ExtractEndpoint extracts the endpoint url from the given manipulator. Note: the given manipulator must be an HTTP Manipulator or it will panic.
func ExtractNamespace ¶
func ExtractNamespace(manipulator manipulate.Manipulator) string
ExtractNamespace extracts the default namespace from the given manipulator. Note: the given manipulator must be an HTTP Manipulator or it will panic.
func ExtractTLSConfig ¶
func ExtractTLSConfig(manipulator manipulate.Manipulator) *tls.Config
ExtractTLSConfig returns a copy of the tls config from the given manipulator. Note: the given manipulator must be an HTTP Manipulator or it will panic.
func ExtractTransport ¶ added in v1.130.0
func ExtractTransport(manipulator manipulate.Manipulator) *http.Transport
ExtractTransport returns the transport used by the given manipulator. This is an advanced feature and the returned transport should not be modified.
func New ¶
func New(ctx context.Context, url string, options ...Option) (manipulate.Manipulator, error)
New returns a maniphttp.Manipulator configured according to the given suite of Option.
func NewSubscriber ¶
func NewSubscriber(manipulator manipulate.Manipulator, options ...SubscriberOption) manipulate.Subscriber
NewSubscriber returns a new subscription.
func NewSubscriberWithEndpoint ¶
func NewSubscriberWithEndpoint(manipulator manipulate.Manipulator, endpoint string, recursive bool) manipulate.Subscriber
NewSubscriberWithEndpoint returns a new subscription connecting to specific endpoint.
func SetGlobalHeaders ¶
func SetGlobalHeaders(manipulator manipulate.Manipulator, headers http.Header)
SetGlobalHeaders sets the given headers to all requests that will be sent. Note: the given manipulator must be an HTTP Manipulator or it will panic.
Types ¶
type Option ¶
type Option func(*httpManipulator)
An Option represents a maniphttp.Manipulator option.
func OptionAdditonalHeaders ¶
OptionAdditonalHeaders sets the additional http.Header that will be sent.
func OptionBackoffCurve ¶ added in v1.121.1
OptionBackoffCurve configures the backoff curve the manipulator will use when performing internal retry operations. Default curve is: 0s, 1s, 4s, 10s, 20s, 30s, 60s
func OptionCredentials ¶
OptionCredentials sets the username and password to use for authentication.
func OptionDefaultRetryFunc ¶ added in v1.61.0
func OptionDefaultRetryFunc(f manipulate.RetryFunc) Option
OptionDefaultRetryFunc sets the default retry func to use if manipulate.Context does not have one.
func OptionDisableBuiltInRetry ¶
func OptionDisableBuiltInRetry() Option
OptionDisableBuiltInRetry disables the auto retry mechanism built in maniphttp Manipulator. By default, the manipulator will silently retry on communication error 3 times after 1s, 2s, and 3s.
func OptionDisableCompression ¶ added in v1.61.0
func OptionDisableCompression() Option
OptionDisableCompression disables the gzip compression in http transport. This only has effect if you don't set a custom transport.
func OptionEncoding ¶
func OptionEncoding(enc elemental.EncodingType) Option
OptionEncoding sets the encoding/decoding type to use.
func OptionHTTPClient ¶
OptionHTTPClient sets internal full *http.Client.
If you use this option you are responsible for configuring the *http.Transport and transport's *tls.Config). OptionHTTPTransport or OptionTLSConfig will have no effect if you use this option.
func OptionHTTPTransport ¶
OptionHTTPTransport sets internal *http.Transport.
If you use this option you are responsible for configuring the *tls.Config. OptionTLSConfig will have no effect if you use this option.
func OptionSendCredentialsAsCookie ¶ added in v1.120.0
OptionSendCredentialsAsCookie configures the manipulator to send the password as a cookie using the provided key.
func OptionSimulateFailures ¶ added in v1.91.0
OptionSimulateFailures will inject random error during low level communication with the remote API.
The key of the map is a float between 0 and 1 that will give the percentage of chance for simulating the failure, and error it should return.
For instance, take the following map:
map[float64]error{ 0.10: manipulate.ErrCannotBuildQuery{Err: fmt.Errorf("Oh no!")}, 0.25: manipulate.ErrCannotCommunicate{Err: fmt.Errorf("Service is gone")}, }
It will return manipulate.ErrCannotBuildQuery around 10% of the requests, manipulate.ErrCannotCommunicate around 25% of the requests. This is obviously designed for simulating backend failures and should not be used in production, obviously.
func OptionStrongBackoffCurve ¶ added in v1.121.1
OptionStrongBackoffCurve configures the strong backoff curve the manipulator will use when performing internal retry operations that necessitate to wait more than usual like a 429 code. Default curve is: 10s, 20s, 30s
func OptionTCPUserTimeout ¶ added in v1.121.0
OptionTCPUserTimeout configures the manipulator to have a custom tcp user timeout.
func OptionTLSClientCertificates ¶ added in v1.130.0
func OptionTLSClientCertificates(cert ...tls.Certificate) Option
OptionTLSClientCertificates sets the Certificate to existing tls.Config. If the is not set, a default one will be used. If you call OptionTLSConfig after, using this option, the tls.Config will be overwritten.
func OptionTLSConfig ¶
OptionTLSConfig sets the tls.Config to use for the manipulator.
func OptionToken ¶
OptionToken sets JWT token. If you use for authentication.
If you also use OptionCredentials or OptionTokenManager, the last one will take precedence.
func OptionTokenManager ¶
func OptionTokenManager(tokenManager manipulate.TokenManager) Option
OptionTokenManager sets manipulate.TokenManager to handle token auto renewal.
If you also use OptionCredentials or OptionToken, the last one will take precedence.
type RetryInfo ¶ added in v1.61.0
A RetryInfo contains information about a retry,
func (RetryInfo) Context ¶ added in v1.61.0
func (i RetryInfo) Context() manipulate.Context
Context returns the manipulate.Context used.
type SubscriberOption ¶
type SubscriberOption func(*subscribeConfig)
SubscriberOption represents option to NewSubscriber.
func SubscriberOptionEndpoint ¶
func SubscriberOptionEndpoint(endpoint string) SubscriberOption
SubscriberOptionEndpoint sets the endpint to connect to. By default it is /events.
func SubscriberOptionNamespace ¶
func SubscriberOptionNamespace(namespace string) SubscriberOption
SubscriberOptionNamespace sets the namespace from where the subscription should start. By default it is the same as the manipulator.
func SubscriberOptionRecursive ¶
func SubscriberOptionRecursive(recursive bool) SubscriberOption
SubscriberOptionRecursive makes the subscriber to listen to events in current namespace and all children.
func SubscriberOptionSupportErrorEvents ¶ added in v1.120.0
func SubscriberOptionSupportErrorEvents() SubscriberOption
SubscriberOptionSupportErrorEvents will result in connecting to the socket server by declaring that you are capable of handling error events.
func SubscriberSendCredentialsAsCookie ¶ added in v1.120.0
func SubscriberSendCredentialsAsCookie(key string) SubscriberOption
SubscriberSendCredentialsAsCookie makes the subscriber send the crendentials as cookie using the provided key