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

client

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Status     string
	Method     string
	URL        string
	Body       []byte
	// Problem holds the decoded RFC 7807 payload when the response
	// carried application/problem+json (or application/json) and the
	// body parsed as a JSON object. nil otherwise; Body always keeps
	// the raw bytes either way.
	Problem *APIProblem
	// Header holds the HTTP response headers, e.g. Retry-After on 429
	// responses.
	Header http.Header
}

APIError is returned for non-2xx responses. It captures the HTTP status, the response headers, the raw response body, and — for JSON error bodies — the decoded RFC 7807 problem details.

func (*APIError) Error

func (e *APIError) Error() string

type APIProblem added in v0.1.0

type APIProblem struct {
	Type     string `json:"type,omitempty"`
	Title    string `json:"title,omitempty"`
	Status   int    `json:"status,omitempty"`
	Detail   string `json:"detail,omitempty"`
	Instance string `json:"instance,omitempty"`

	// Extensions holds any non-standard members (e.g. a per-field
	// "errors" array) keyed by member name.
	Extensions map[string]json.RawMessage `json:"-"`
}

APIProblem is an RFC 7807 "problem details" object. Members beyond the five standard ones are preserved in Extensions as raw JSON.

func (*APIProblem) UnmarshalJSON added in v0.1.0

func (p *APIProblem) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the standard RFC 7807 members and captures everything else in Extensions.

type APIResponse added in v0.3.0

type APIResponse struct {
	StatusCode int
	Header     http.Header
}

APIResponse carries the HTTP metadata of a response — the exact status code (200 vs 201 vs 204, ...) and the response headers. Every generated method returns it just before the error, and it is non-nil whenever an HTTP response was received — including non-2xx responses (alongside the *APIError) and 2xx responses whose body failed to read or decode. It is nil only when no response arrived at all (request construction or transport errors).

type Client

type Client struct {
	// BaseURL is prepended to every request path (no trailing slash).
	BaseURL string
	// HTTP is the underlying HTTP client. nil falls back to http.DefaultClient.
	HTTP *http.Client
	// DefaultHeaders are merged onto every request before per-call headers.
	DefaultHeaders http.Header
}

Client is the typed HTTP client for the generated API.

func NewClient

func NewClient(baseURL string) *Client

NewClient returns a Client targeting baseURL.

func (*Client) CreateItem

func (c *Client) CreateItem(ctx context.Context, idempotencyKey string, body CreateItemBody) (*Item, *APIResponse, error)

Create an item

func (*Client) DeleteItem

func (c *Client) DeleteItem(ctx context.Context, id int64, idempotencyKey string, ifMatch string) (*APIResponse, error)

Delete an item

func (*Client) ExportItems added in v0.1.0

func (c *Client) ExportItems(ctx context.Context) (io.ReadCloser, *APIResponse, error)

Export items as CSV

The returned io.ReadCloser streams the raw text/csv response body; the caller must close it.

func (*Client) GetItem

Get an item

func (*Client) Healthz

func (c *Client) Healthz(ctx context.Context) (*Health, *APIResponse, error)

Liveness check

func (*Client) ImportItems added in v0.1.0

func (c *Client) ImportItems(ctx context.Context, body io.Reader) (*APIResponse, error)

Bulk-import items from a CSV upload

The request body is streamed as application/octet-stream; it is not buffered.

func (*Client) ListItems

func (c *Client) ListItems(ctx context.Context, cursor *string, limit *int64) (*ItemList, *APIResponse, error)

List items

type CreateItemBody

type CreateItemBody struct {
	Name string `json:"name"`
}

type GetItemResponseHeaders added in v0.1.0

type GetItemResponseHeaders struct {
	CacheControl string
	// Entity tag for the returned item
	Etag string
}

GetItemResponseHeaders carries the response headers declared on GetItem's success response. Headers absent from the response are left as zero values.

type Health

type Health struct {
	Status string `json:"status"`
}

type Item

type Item struct {
	Id        int64  `json:"id"`
	Name      string `json:"name"`
	CreatedAt string `json:"created_at"`
}

type ItemList

type ItemList struct {
	Items []Item `json:"items"`
}

type Problem

type Problem struct {
	Title  string  `json:"title"`
	Status int64   `json:"status"`
	Detail *string `json:"detail,omitempty"`
}

Jump to

Keyboard shortcuts

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