core

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoRequest

func DoRequest(
	ctx context.Context,
	client HTTPClient,
	url string,
	method string,
	request any,
	response any,
	responseIsOptional bool,
	endpointHeaders http.Header,
	errorDecoder ErrorDecoder,
) error

DoRequest issues a JSON request to the given url.

Types

type APIError

type APIError struct {
	StatusCode int `json:"-"`
	// contains filtered or unexported fields
}

APIError is a lightweight wrapper around the standard error interface that preserves the status code from the RPC, if any.

func NewAPIError

func NewAPIError(statusCode int, err error) *APIError

NewAPIError constructs a new API error.

func (*APIError) Error

func (a *APIError) Error() string

Error returns the API error's message.

func (*APIError) Unwrap

func (a *APIError) Unwrap() error

Unwrap returns the underlying error. This also makes the error compatible with errors.As and errors.Is.

type ClientOption

type ClientOption func(*ClientOptions)

ClientOption adapts the behavior of the generated client.

type ClientOptions

type ClientOptions struct {
	BaseURL    string
	HTTPClient HTTPClient
	HTTPHeader http.Header
	Token      string
}

ClientOptions defines all of the possible client options. This type is primarily used by the generated code and is not meant to be used directly; use ClientOption instead.

func NewClientOptions

func NewClientOptions() *ClientOptions

NewClientOptions returns a new *ClientOptions value. This function is primarily used by the generated code and is not meant to be used directly; use ClientOption instead.

func (*ClientOptions) ToHeader

func (c *ClientOptions) ToHeader() http.Header

ToHeader maps the configured client options into a http.Header issued on every request.

type ErrorDecoder

type ErrorDecoder func(statusCode int, body io.Reader) error

ErrorDecoder decodes *http.Response errors and returns a typed API error (e.g. *APIError).

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient is an interface for a subset of the *http.Client.

type Optional added in v0.0.28

type Optional[T any] struct {
	Value T
	Null  bool
}

Optional is a wrapper used to distinguish zero values from null or omitted fields.

To instantiate an Optional, use the `Optional()` and `Null()` helpers exported from the root package.

func (*Optional[T]) MarshalJSON added in v0.0.28

func (o *Optional[T]) MarshalJSON() ([]byte, error)

func (*Optional[T]) String added in v0.0.28

func (o *Optional[T]) String() string

Jump to

Keyboard shortcuts

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