client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 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
}

APIError is returned for non-2xx responses. It captures the HTTP status, 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 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, error)

Create an item

func (*Client) DeleteItem

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

Delete an item

func (*Client) ExportItems added in v0.1.0

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

Export items as CSV

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

func (*Client) GetItem

func (c *Client) GetItem(ctx context.Context, id int64) (*Item, GetItemResponseHeaders, error)

Get an item

func (*Client) Healthz

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

Liveness check

func (*Client) ImportItems added in v0.1.0

func (c *Client) ImportItems(ctx context.Context, body io.Reader) 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, 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