Documentation
¶
Overview ¶
Package apiutil holds what the HTTP API and the WebSocket endpoint share: RESP → JSON conversion, JSON → command parsing, and credential checks.
Index ¶
- Constants
- Variables
- func AppendFloat(b []byte, f float64) []byte
- func AppendJSON(b []byte, v resp.Value) []byte
- func AppendString(b []byte, s string) []byte
- func ErrorStatus(msg string) int
- func JSON(v resp.Value) json.RawMessage
- func Login(e *command.Engine, token string) (string, error)
- func LoginUser(e *command.Engine, user, pass string) (string, error)
- func Namespace(ns string) (string, error)
- func ParseCommand(raw []byte) ([]string, error)
- func ParseCommands(raw []byte) ([][]string, error)
- func RequestUser(e *command.Engine, r *http.Request, allowQuery bool) (string, error)
Constants ¶
const MaxBody = 16 << 20
MaxBody is the largest request body / WebSocket message accepted (16 MB).
Variables ¶
ErrUnauthorized means credentials were missing or wrong.
Functions ¶
func AppendFloat ¶
AppendFloat writes a JSON number; non-finite values become strings.
func AppendJSON ¶
AppendJSON appends v encoded as JSON:
simple/bulk → string, integer → number, double → number ("inf", "-inf",
"nan" as strings), bool → bool, null → null, array/set/push → array,
map → object (keys stringified, order kept), error → {"error": "..."}.
func AppendString ¶
AppendString appends s as a JSON string. Invalid UTF-8 becomes U+FFFD.
func ErrorStatus ¶
ErrorStatus maps a command error to an HTTP status.
func Login ¶
Login checks credentials. token is "password" (default user) or "user:password". An empty token is accepted only when the server has no password. Returns the user to run commands as.
func Namespace ¶
Namespace validates the X-CacheBoy-Namespace header value. "" and "default" select the default namespace.
func ParseCommand ¶
ParseCommand decodes a JSON array of strings/numbers into command args.
func ParseCommands ¶
ParseCommands decodes a JSON array of commands (pipeline / multi bodies).
Types ¶
This section is empty.