api

package
v0.0.0-...-230c208 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 28 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 api is the HTTP surface. It is deliberately split into two route trees that never share middleware: one for humans holding a passkey session, one for agents holding a bearer token. See router.go.

Index

Constants

View Source
const (
	CodeValidation   = "VALIDATION_ERROR"
	CodeUnauthorized = "UNAUTHORIZED"
	CodeForbidden    = "FORBIDDEN"
	CodeNotFound     = "NOT_FOUND"
	CodeConflict     = "CONFLICT"
	CodeRateLimited  = "RATE_LIMITED"
	CodeInternal     = "INTERNAL_ERROR"
	// CodeStepUpRequired tells the client to run a fresh passkey assertion and
	// retry. It is distinct from FORBIDDEN because it is recoverable: the SPA
	// prompts, the user touches the sensor, the retry succeeds.
	CodeStepUpRequired = "STEP_UP_REQUIRED"
)

Error codes, per house style.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON(w http.ResponseWriter, r *http.Request, dst any) bool

DecodeJSON reads a bounded JSON body, rejecting unknown fields so a typo in an agent's request surfaces as an error rather than a silently ignored field.

func Forbidden

func Forbidden(w http.ResponseWriter, msg string)

Forbidden is returned when a valid principal lacks the privilege.

func Internal

func Internal(w http.ResponseWriter, err error, where string)

Internal logs the real error and returns a blank one.

func SessionFrom

func SessionFrom(ctx context.Context) *store.Session

SessionFrom returns the live session, or nil.

func TokenFrom

func TokenFrom(ctx context.Context) *store.APIToken

TokenFrom returns the authenticated agent token, or nil.

func Unauthorized

func Unauthorized(w http.ResponseWriter)

Unauthorized is the single response for every failed authentication, whatever the underlying cause. A caller must not be able to tell a missing cookie from an expired one, or an unknown token from a revoked one.

func UserFrom

func UserFrom(ctx context.Context) *store.User

UserFrom returns the authenticated human, or nil.

func WriteError

func WriteError(w http.ResponseWriter, status int, code, msg string)

WriteError emits {"error": {message, code}}.

Messages are written for a human reading a phone, not for a debugger: they never contain a stack trace, a SQL fragment, a file path, or any hint about which of several checks failed.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, data any)

WriteJSON emits {"data": …}.

func WriteList

func WriteList(w http.ResponseWriter, status int, data any, meta Meta)

WriteList emits {"data": […], "meta": {…}}.

Types

type Bus

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

Bus fans realtime events out to a user's connected browsers.

Per-user, never global: an event is delivered only to sockets authenticated as the user it concerns. Sends are non-blocking, because one wedged phone must not stall an answer that another device is waiting on.

func NewBus

func NewBus() *Bus

NewBus builds an empty bus.

func (*Bus) Publish

func (b *Bus) Publish(userID string, event any)

Publish delivers an event to every socket belonging to a user.

func (*Bus) Subscribe

func (b *Bus) Subscribe(userID string) (<-chan any, func())

Subscribe registers a listener for one user's events.

type Meta

type Meta struct {
	Total   int `json:"total"`
	Page    int `json:"page"`
	PerPage int `json:"per_page"`
}

Meta accompanies list responses.

type Server

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

Server holds everything the HTTP layer needs.

func NewServer

func NewServer(cfg *config.Config, st *store.Store, a *auth.Service, rv *review.Service,
	tm *terminal.Service, ptys *terminal.Manager, nt *notify.Service, bus *Bus,
	pastes *paste.Store, assets *review.AssetStore, tk *tasks.Service, version string) *Server

NewServer wires the routes.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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