api

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeHeaders

func SanitizeHeaders(h map[string][]string) map[string][]string

func WithLogAttr

func WithLogAttr(ctx context.Context, key, value string) context.Context

WithLogAttr adds a single key-value pair into the context log attributes map. All entries are automatically appended to outgoing request and incoming response log messages.

func WithLogAttrs

func WithLogAttrs(ctx context.Context, attrs map[string]string) context.Context

WithLogAttrs adds multiple key-value pairs into the context log attributes map.

func WithTokenRefreshBuffer

func WithTokenRefreshBuffer(ctx context.Context, value time.Duration) context.Context

Types

type ApiError

type ApiError struct {
	StatusCode int
	Body       []byte
}

ApiError is the typed error returned by RestyClient.R for non-2xx responses. StatusCode is the HTTP status. Body is the raw response body — captured verbatim so callers can surface server-side error messages in their own error chains without doing a second roundtrip. Body is truncated at 64 KiB to bound memory; servers that need to communicate larger error payloads should use a structured error contract instead.

func (*ApiError) Error

func (e *ApiError) Error() string

type BearerTokenManager

type BearerTokenManager struct {
	sync.RWMutex
	Token     string
	ExpiresAt time.Time
	Refresher BearerTokenRefresher
}

func (*BearerTokenManager) GetToken

func (tm *BearerTokenManager) GetToken(ctx context.Context) (string, error)

type BearerTokenRefresher

type BearerTokenRefresher func(context.Context) (string, time.Time, error)

type ClientOption

type ClientOption struct{}
var CO ClientOption

func (*ClientOption) WithAuthToken

func (co *ClientOption) WithAuthToken(token string) RestyClientOption

func (*ClientOption) WithBaseUrl

func (co *ClientOption) WithBaseUrl(url string) RestyClientOption

func (*ClientOption) WithBasicAuth

func (co *ClientOption) WithBasicAuth(username, password string) RestyClientOption

func (*ClientOption) WithDebug

func (co *ClientOption) WithDebug(d bool) RestyClientOption

func (*ClientOption) WithHeader

func (co *ClientOption) WithHeader(key, value string) RestyClientOption

func (*ClientOption) WithHeaders

func (co *ClientOption) WithHeaders(headers map[string]string) RestyClientOption

func (*ClientOption) WithRequestLogger

func (co *ClientOption) WithRequestLogger(logger *slog.Logger) RestyClientOption

func (*ClientOption) WithRetryCount

func (co *ClientOption) WithRetryCount(count int) RestyClientOption

func (*ClientOption) WithTimeout

func (co *ClientOption) WithTimeout(timeout time.Duration) RestyClientOption

func (*ClientOption) WithTransport

func (co *ClientOption) WithTransport(rt http.RoundTripper) RestyClientOption

type RequestOption

type RequestOption struct{}
var RO RequestOption

func (*RequestOption) WithAuthToken

func (ro *RequestOption) WithAuthToken(token string) RestyRequestOption

func (*RequestOption) WithBasicAuth

func (ro *RequestOption) WithBasicAuth(username, password string) RestyRequestOption

func (*RequestOption) WithBody

func (ro *RequestOption) WithBody(body any) RestyRequestOption

func (*RequestOption) WithDebug

func (ro *RequestOption) WithDebug(d bool) RestyRequestOption

func (*RequestOption) WithHeader

func (ro *RequestOption) WithHeader(key, value string) RestyRequestOption

func (*RequestOption) WithHeaders

func (ro *RequestOption) WithHeaders(headers map[string]string) RestyRequestOption

func (*RequestOption) WithPathParam

func (ro *RequestOption) WithPathParam(param, value string) RestyRequestOption

func (*RequestOption) WithPathParams

func (ro *RequestOption) WithPathParams(params map[string]string) RestyRequestOption

func (*RequestOption) WithQueryParam

func (ro *RequestOption) WithQueryParam(param, value string) RestyRequestOption

func (*RequestOption) WithQueryParams

func (ro *RequestOption) WithQueryParams(params map[string]string) RestyRequestOption

type RestyClient

type RestyClient struct {
	*resty.Client
}

func NewRestClient

func NewRestClient(baseURL string, opts ...RestyClientOption) *RestyClient

func (*RestyClient) R

func (rc *RestyClient) R(ctx context.Context, method, path string, result any, opts ...RestyRequestOption) error

type RestyClientOption

type RestyClientOption func(*resty.Client)

type RestyRequestOption

type RestyRequestOption func(*resty.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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