Help us shape the future of Go! Take the 2026 Go Developer Survey

client

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// APIUrl is the URL of our API.
	APIUrl = "https://api.sumup.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func New

func New(opts ...ClientOption) *Client

New creates new HTTP API client. The client is by default configured with environment variables (e.g. `SUMUP_API_KEY`). To override the default configuration use [ClientOption]s.

func (*Client) Call

func (c *Client) Call(
	ctx context.Context, method, path string, opts ...RequestOption,
) (*http.Response, error)

Call executes an API call. Use [RequestOption]s to configure the request.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends an HTTP request and returns an HTTP response, following policy (such as redirects, cookies, auth) as configured on the HTTP client.

func (*Client) NewRequest

func (c *Client) NewRequest(
	ctx context.Context, method, path string, body io.Reader,
) (*http.Request, error)

NewRequest returns a new http.Request given a method, URL, and optional body.

NewRequest returns a Request suitable for use with Client.Do.

type ClientOption

type ClientOption func(c *Client) error

ClientOption is an option for the API client.

func WithAPIKey

func WithAPIKey(key string) ClientOption

WithAPIKey returns a ClientOption that configures the client with an API key for authorization.

func WithBaseURL

func WithBaseURL(base string) ClientOption

WithBaseURL returns a ClientOption that configures the client with a base URL that the individual API call paths will be resolved against.

func WithClient

func WithClient(client *http.Client) ClientOption

WithClient returns a ClientOption that configures the client to use a specific http client for underlying requests.

type RequestOption

type RequestOption func(req *request) error

RequestOption is an option for the request made by the Client.

func WithHTTPClient

func WithHTTPClient(client *http.Client) RequestOption

WithHTTPClient returns a RequestOption that overrides the underlying http.Client of the service used to make the request.

func WithHeader

func WithHeader(key, value string) RequestOption

WithHeader returns a RequestOption that sets a header key-value pair. Any previously set value will be overwritten.

func WithJSONBody

func WithJSONBody(v any) RequestOption

WithBody returns a RequestOption that sets the request body as a JSON of the value v.

func WithQueryValues

func WithQueryValues(q url.Values) RequestOption

WithQueryValues returns a RequestOption that sets the request query params.

Jump to

Keyboard shortcuts

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