httpc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 11 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 httpc is a small bearer-token JSON client with typed errors.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized = errors.New(`unauthorized; run "lfed auth login"`)
	ErrForbidden    = errors.New("forbidden")
	ErrNotFound     = errors.New("not found")
	ErrConflict     = errors.New("conflict")
)

Sentinel errors for the HTTP statuses a command may handle. Do returns errors that wrap them, so callers use errors.Is.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status int
	// Body is the FastAPI `detail` when present, else the raw body.
	Body string
}

APIError is any other non-2xx response.

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client sends JSON requests with a bearer token.

func New

func New(baseURL, token string, opts ...Option) *Client

New builds a Client. Trailing slashes on baseURL are stripped so paths can start with "/".

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body, out any) error

Do sends method path with body marshalled as JSON (nil sends no body) and decodes a 2xx response into out (nil discards it; 204 is fine).

type Option

type Option func(*Client)

Option configures New.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient replaces the default 30-second-timeout client.

func WithUserAgent

func WithUserAgent(name string) Option

WithUserAgent sets `User-Agent: lfed-plugin/<name>`.

Jump to

Keyboard shortcuts

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