Documentation
¶
Index ¶
- Variables
- func GetResponseErrorCode(err error) int
- func WithHeader(key, value string) func(http.Header)
- type DecodeError
- type Decoder
- type DialOptions
- type Encoder
- type HTTPClient
- func (c *HTTPClient) Delete(path string, data any, dest any) error
- func (c *HTTPClient) Do(method, path string, body io.Reader, dest any, hdrs ...HeaderFunc) error
- func (c *HTTPClient) DoHeader(method, path string, body io.Reader, dest any, hdrs ...HeaderFunc) (http.Header, error)
- func (c *HTTPClient) Get(path string, params url.Values, dest any) error
- func (c *HTTPClient) Patch(path string, data any, dest any) error
- func (c *HTTPClient) Post(path string, data any, dest any, hdrs ...HeaderFunc) error
- func (c *HTTPClient) Put(path string, data any, dest any) error
- type HTTPOption
- func WithBefore(fn func(*http.Request) error) HTTPOption
- func WithClient(c *http.Client) HTTPOption
- func WithDecoder(fn func([]byte, any) error) HTTPOption
- func WithEncoder(fn func(obj any) ([]byte, error)) HTTPOption
- func WithLoggedBodies() HTTPOption
- func WithLogger(lg Logger) HTTPOption
- func WithMaxStatus(code int) HTTPOption
- func WithRateLimit(r rate.Limit, b int) HTTPOption
- func WithSensitiveHeader(keys ...string) HTTPOption
- type HeaderFunc
- type Logger
- type PingHandler
- type ResponseError
- type WSClient
- type WSOption
- func WithDialOptions(fn func() (*DialOptions, error)) WSOption
- func WithEndpointFunc(fn func() (string, error)) WSOption
- func WithMaxAttempts(n int) WSOption
- func WithPingHandler(ph PingHandler) WSOption
- func WithPingInterval(i time.Duration) WSOption
- func WithReconnectBackoff(maxBackoff time.Duration) WSOption
- func WithStaleDetection(timeout time.Duration) WSOption
- func WithWSEncoder(fn func(any) ([]byte, error)) WSOption
- func WithWSHandler(fn func([]byte) error) WSOption
- func WithWSLogger(l Logger) WSOption
- func WithWSOnClose(fn func(*WSClient) error) WSOption
- func WithWSOnOpen(fn func(*WSClient) error) WSOption
- func WithWriteLimiter(r rate.Limit, b int) WSOption
Constants ¶
This section is empty.
Variables ¶
var ErrNotConnected = errors.New("websocket not connected")
var (
MaxAttemptsError = errors.New("max connection attempts")
)
Functions ¶
func GetResponseErrorCode ¶
func WithHeader ¶
Types ¶
type DecodeError ¶
func (DecodeError) Error ¶
func (e DecodeError) Error() string
type DialOptions ¶
type DialOptions = websocket.DialOptions
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
func NewHTTPClient ¶
func NewHTTPClient(root string, opts ...HTTPOption) *HTTPClient
func (*HTTPClient) Do ¶
func (c *HTTPClient) Do(method, path string, body io.Reader, dest any, hdrs ...HeaderFunc) error
func (*HTTPClient) DoHeader ¶
func (c *HTTPClient) DoHeader(method, path string, body io.Reader, dest any, hdrs ...HeaderFunc) (http.Header, error)
func (*HTTPClient) Post ¶
func (c *HTTPClient) Post(path string, data any, dest any, hdrs ...HeaderFunc) error
type HTTPOption ¶
type HTTPOption func(*HTTPClient)
func WithBefore ¶
func WithBefore(fn func(*http.Request) error) HTTPOption
func WithClient ¶
func WithClient(c *http.Client) HTTPOption
func WithDecoder ¶
func WithDecoder(fn func([]byte, any) error) HTTPOption
func WithEncoder ¶
func WithEncoder(fn func(obj any) ([]byte, error)) HTTPOption
func WithLoggedBodies ¶
func WithLoggedBodies() HTTPOption
func WithLogger ¶
func WithLogger(lg Logger) HTTPOption
func WithMaxStatus ¶
func WithMaxStatus(code int) HTTPOption
func WithRateLimit ¶
func WithRateLimit(r rate.Limit, b int) HTTPOption
func WithSensitiveHeader ¶
func WithSensitiveHeader(keys ...string) HTTPOption
type HeaderFunc ¶
type ResponseError ¶
func (ResponseError) Error ¶
func (e ResponseError) Error() string
type WSClient ¶
type WSClient struct {
// contains filtered or unexported fields
}
func NewWSClient ¶
func (*WSClient) IsConnected ¶
IsConnected returns true if the WebSocket is currently connected.
type WSOption ¶
type WSOption func(*WSClient)
func WithDialOptions ¶
func WithDialOptions(fn func() (*DialOptions, error)) WSOption
WithDialOptions allows callers to inject dial options in to the underlying lib.
func WithEndpointFunc ¶
func WithMaxAttempts ¶
func WithPingHandler ¶
func WithPingHandler(ph PingHandler) WSOption
func WithPingInterval ¶
WithPingInterval sets the ping interval
func WithReconnectBackoff ¶
WithReconnect enables exponential backoff behavior on reconnect.
func WithStaleDetection ¶
WithStaleDetection, if configured, will create a goroutine that asserts on the websocket having received some message within some recent time interval. If the assertion fails, the connection is closed, and whatever reconnect behavior has been configured will take over.
func WithWSEncoder ¶
WithWSEncoder sets the encoder for objects written to the client
func WithWSHandler ¶
WithWSHandler sets the global message handler for the client.
func WithWSLogger ¶
WithWSLogger sets the logger for the websocket client.
func WithWSOnClose ¶
WithWSOnOpen sets the callback called whenver a connection is closed.
func WithWSOnOpen ¶
WithWSOnOpen sets the callback called whenver a new connection is opened.