sdk

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRequestInterceptor added in v0.4.9

func AddRequestInterceptor(interceptor func(ctx context.Context, req *http.Request) error) opt.Option[Config]

func AddResponseInterceptor added in v0.4.9

func AddResponseInterceptor(interceptor func(ctx context.Context, resp *http.Response) error) opt.Option[Config]

func ApiKeyAuth

func ApiKeyAuth(headerName, headerValue string) opt.Option[Config]

func BearerAuth

func BearerAuth(token string) opt.Option[Config]

func Execute

func Execute[Response any](
	ctx context.Context,
	endpoint Client,
	request *Request,
) (*Response, error)

func SetErrorResponseType added in v0.4.9

func SetErrorResponseType[T any](handler ...func(response T) string) opt.Option[Config]

func WithFormBody

func WithFormBody[Body any](value Body) opt.Option[Request]

func WithHeader

func WithHeader(name string, value string) opt.Option[Request]

func WithJsonBody

func WithJsonBody[Body any](value Body) opt.Option[Request]

func WithMultipartFormBody

func WithMultipartFormBody(formWriter multipart.Writer, value *bytes.Buffer) opt.Option[Request]

func WithQueryFloat

func WithQueryFloat(name string, value any) opt.Option[Request]

func WithQueryInt

func WithQueryInt(name string, value any) opt.Option[Request]

func WithQueryParam

func WithQueryParam(name string, value string) opt.Option[Request]

func WithQueryStrings

func WithQueryStrings(name string, values ...string) opt.Option[Request]

func WithQueryStruct added in v0.4.9

func WithQueryStruct[T any](value T) opt.Option[Request]

func WithTimeout

func WithTimeout(ttl time.Duration) opt.Option[Request]

Types

type Client

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

func New

func New(endpoint string, opts ...opt.Option[Config]) (*Client, error)

func (Client) Request

func (c Client) Request(method, path string, opts ...opt.Option[Request]) *Request

type Config

type Config struct {
	Timeout              time.Duration
	RequestInterceptors  []RequestInterceptor
	ResponseInterceptors []ResponseInterceptor
}

func NewConfig

func NewConfig(opts ...opt.Option[Config]) Config

func (*Config) InterceptRequest

func (c *Config) InterceptRequest(ctx context.Context, req *http.Request) error

func (*Config) InterceptResponse

func (c *Config) InterceptResponse(ctx context.Context, resp *http.Response) error

type Endpoint

type Endpoint interface {
	Config() Config
}

type ErrorResponse added in v0.4.9

type ErrorResponse[T any] struct {
	Response T
}

func (ErrorResponse[T]) Error added in v0.4.9

func (e ErrorResponse[T]) Error() string

type Request

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

type RequestInterceptor

type RequestInterceptor func(ctx context.Context, req *http.Request) error

type ResponseInterceptor

type ResponseInterceptor func(ctx context.Context, resp *http.Response) error

Jump to

Keyboard shortcuts

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