testclient

package
v0.0.0-...-42663ac Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertHTTPError

func AssertHTTPError(err error, code int) *be.Outcome

func Paged

func Paged[
	Req PageRequest,
	Res PageResponse[Item],
	Item any,
](ctx context.Context, baseReq Req, call func(context.Context, Req) (Res, error), callback func(Item) error) error

Types

type API

type API struct {
	BaseURL string

	Client *http.Client

	Logger func(*RequestLog)

	Auth AuthProvider
}

func NewAPI

func NewAPI(baseURL string) (*API, error)

func (*API) Request

func (api *API) Request(ctx context.Context, method string, path string, body interface{}, response interface{}) error

type APIError

type APIError struct {
	StatusCode int
}

func (*APIError) Error

func (e *APIError) Error() string

type AuthProvider

type AuthProvider interface {
	// Authenticate should set whatever headers etc are needed on the request.
	// It should cache results where a server call is involved, and it must not
	// attempt to authenticate where the request is already an auth request.
	Authenticate(req *http.Request) error
}

type BearerToken

type BearerToken string

func (BearerToken) Authenticate

func (t BearerToken) Authenticate(req *http.Request) error

type PageRequest

type PageRequest interface {
	SetPageToken(string)
}

type PageResponse

type PageResponse[Item any] interface {
	GetPageToken() *string
	GetItems() []Item
}

type RequestLog

type RequestLog struct {
	Method         string
	Path           string
	ResponseStatus int
	RequestBody    interface{}
	RequestHeaders http.Header
	ResponseBody   interface{}
	ResponseHeader http.Header
	Error          error
}

Jump to

Keyboard shortcuts

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