client

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package client is a thin, strict HTTP client for the New API admin surface.

It exists instead of a generated OpenAPI client because the admin API is not fully described by any spec: the two behaviours that break naive clients are handled here explicitly.

  1. New API answers a failed call with HTTP 200 and {"success": false}. Checking the status code alone reports success on every rejection.
  2. The admin surface needs both an Authorization bearer token and a New-Api-User header carrying the numeric user id.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound   = errors.New("not found (404)")
	ErrUnauth     = errors.New("unauthorized (401/403): the access token is invalid, expired, or missing a scope")
	ErrRateLimit  = errors.New("rate limited (429)")
	ErrUpstream   = errors.New("upstream error (5xx)")
	ErrBadRequest = errors.New("bad request (400)")
)

Sentinel errors surfaced to the agent so it can react without parsing prose.

View Source
var ErrReadOnly = errors.New("server is in read-only mode: NEWAPI_READ_ONLY=true")

ErrReadOnly is returned for a mutating call while the server is in read-only mode.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
	Sentinel   error
}

APIError describes a rejected call.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

type Client

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

Client talks to one New API instance.

func NewWithOptions

func NewWithOptions(o Options) *Client

NewWithOptions builds a client from explicit options.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the configured origin.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, query url.Values, body any) (*Response, error)

Do performs one admin call.

path must start with "/api/". query may be nil. body may be nil, a json.RawMessage, or any value that encodes to JSON.

func (*Client) ReadOnly

func (c *Client) ReadOnly() bool

ReadOnly reports whether mutating calls are blocked.

type Envelope

type Envelope struct {
	Success bool            `json:"success"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data"`
}

Envelope is New API's universal JSON response wrapper.

type Options

type Options struct {
	BaseURL  string
	Token    string
	UserID   string
	HTTP     *http.Client
	ReadOnly bool
}

Options configures NewWithOptions.

type Response

type Response struct {
	StatusCode int
	Body       []byte
	// Envelope is non-nil when the body parsed as New API's wrapper.
	Envelope *Envelope
}

Response is one completed upstream call.

func (*Response) Data

func (r *Response) Data() json.RawMessage

Data returns the envelope's data payload, or the raw body when there is no envelope.

func (*Response) Decode

func (r *Response) Decode(v any) error

Decode unmarshals the response payload into v.

Jump to

Keyboard shortcuts

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