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
- func DecodeJSON(w http.ResponseWriter, r *http.Request, dst any) bool
- func Forbidden(w http.ResponseWriter, msg string)
- func Internal(w http.ResponseWriter, err error, where string)
- func SessionFrom(ctx context.Context) *store.Session
- func TokenFrom(ctx context.Context) *store.APIToken
- func Unauthorized(w http.ResponseWriter)
- func UserFrom(ctx context.Context) *store.User
- func WriteError(w http.ResponseWriter, status int, code, msg string)
- func WriteJSON(w http.ResponseWriter, status int, data any)
- func WriteList(w http.ResponseWriter, status int, data any, meta Meta)
- type Bus
- type Meta
- type Server
Constants ¶
const ( CodeValidation = "VALIDATION_ERROR" 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 ¶
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 ¶
SessionFrom returns the live session, 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 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.
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.
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.