package api import "net/http" // The console is a second binary that serves this API's authentication and // session handling in front of a different backend. These exports let it // register routes of its own behind the same checks, without the api package // knowing anything about the console. // Protect wraps h with this server's authentication, write-permission check // and rate limit. write marks a mutating route that a read-only key must not // reach. The authenticated Principal is available through PrincipalFrom. func (s *Server) Protect(h http.Handler, write bool) http.Handler { return s.authed(h.ServeHTTP, write) } // WriteJSON answers with v as JSON, the way every handler here does. func WriteJSON(w http.ResponseWriter, code int, v any) { writeJSON(w, code, v) } // WriteError answers with the standard {"error": msg} body. func WriteError(w http.ResponseWriter, code int, msg string) { writeError(w, code, msg) } // DecodeJSON reads a size-limited JSON request body. func DecodeJSON(r *http.Request, v any) error { return decodeJSON(r, v) }