apiutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 14 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 apiutil holds what the HTTP API and the WebSocket endpoint share: RESP → JSON conversion, JSON → command parsing, and credential checks.

Index

Constants

View Source
const MaxBody = 16 << 20

MaxBody is the largest request body / WebSocket message accepted (16 MB).

Variables

View Source
var ErrUnauthorized = errors.New("NOAUTH Authentication required.")

ErrUnauthorized means credentials were missing or wrong.

Functions

func AppendFloat

func AppendFloat(b []byte, f float64) []byte

AppendFloat writes a JSON number; non-finite values become strings.

func AppendJSON

func AppendJSON(b []byte, v resp.Value) []byte

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

func AppendString(b []byte, s string) []byte

AppendString appends s as a JSON string. Invalid UTF-8 becomes U+FFFD.

func ErrorStatus

func ErrorStatus(msg string) int

ErrorStatus maps a command error to an HTTP status.

func JSON

func JSON(v resp.Value) json.RawMessage

JSON returns v as JSON text.

func Login

func Login(e *command.Engine, token string) (string, error)

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 LoginUser

func LoginUser(e *command.Engine, user, pass string) (string, error)

LoginUser checks an explicit user/password pair.

func Namespace

func Namespace(ns string) (string, error)

Namespace validates the X-CacheBoy-Namespace header value. "" and "default" select the default namespace.

func ParseCommand

func ParseCommand(raw []byte) ([]string, error)

ParseCommand decodes a JSON array of strings/numbers into command args.

func ParseCommands

func ParseCommands(raw []byte) ([][]string, error)

ParseCommands decodes a JSON array of commands (pipeline / multi bodies).

func RequestUser

func RequestUser(e *command.Engine, r *http.Request, allowQuery bool) (string, error)

RequestUser authenticates an HTTP request from its Authorization header ("Bearer <password>", "Bearer <user:password>" or Basic user:pass) and, when allowQuery is set, a ?token= parameter.

Types

This section is empty.

Jump to

Keyboard shortcuts

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