Documentation
¶
Index ¶
- Constants
- func EncodeCursor(offset int) string
- func NextLink(r *http.Request, nextCursor string, limit int) string
- func ParseCursor(raw string) (int, error)
- func ParseLimit(r *http.Request, defaultLimit, maxLimit int) (int, error)
- func QueryInt(r *http.Request, key string, fallback, minValue, maxValue int) (int, error)
- func QueryRFC3339Time(r *http.Request, key string) (time.Time, error)
- func WriteBodyDecodeError(w http.ResponseWriter, err error)
- func WriteEnvelope(w http.ResponseWriter, status int, code, message string)
- func WriteError(w http.ResponseWriter, logger *zap.Logger, err error)
- func WriteJSON(w http.ResponseWriter, status int, payload any)
- func WriteMethodNotAllowed(w http.ResponseWriter, methods ...string)
- type CursorPayload
- type Error
- func BadRequest(code, message string, cause ...error) *Error
- func Conflict(message string, cause ...error) *Error
- func Forbidden(message string, cause ...error) *Error
- func Internal(message string, cause ...error) *Error
- func NotFound(message string, cause ...error) *Error
- func ServiceUnavailable(code, message string, cause ...error) *Error
- func Unauthorized(message string, cause ...error) *Error
- type Meta
Constants ¶
const ( CodeInternalError = "internal_error" CodeInvalidRequestBody = "invalid_request_body" CodeRequestTooLarge = "request_too_large" CodeInvalidQueryParam = "invalid_query_param" CodeMethodNotAllowed = "method_not_allowed" CodeForbidden = "forbidden" CodeNotFound = "not_found" CodeConflict = "conflict" CodeQueryFailed = "query_failed" CodeAuthFailed = "auth_failed" CodeInvalidVersionTag = "invalid_version_tag" CodeTooManyRequests = "too_many_requests" )
Stable machine-readable error codes. Wording in human messages may change; codes must not be derived from message text at runtime.
const ( DefaultListLimit = 50 MaxListLimit = 200 )
const ApplyMaxBytes = 64 * 1024
Variables ¶
This section is empty.
Functions ¶
func EncodeCursor ¶
EncodeCursor returns the next opaque cursor for a list page.
func NextLink ¶
NextLink builds an absolute or path-only next URL with cursor and limit query params.
func ParseCursor ¶
ParseCursor decodes an opaque cursor or returns offset 0 when absent.
func ParseLimit ¶
ParseLimit reads limit with defaults and strict bounds. Invalid values return an *Error.
func QueryInt ¶
QueryInt parses a required-shape integer query param. Empty uses fallback. Non-integer or out-of-range values return *Error with CodeInvalidQueryParam.
func QueryRFC3339Time ¶
QueryRFC3339Time parses an optional RFC3339 timestamp query param.
func WriteBodyDecodeError ¶
func WriteBodyDecodeError(w http.ResponseWriter, err error)
WriteBodyDecodeError maps decode failures to the standard error envelope.
func WriteEnvelope ¶
func WriteEnvelope(w http.ResponseWriter, status int, code, message string)
WriteEnvelope writes {"error":"<code>","message":"<description>"}.
func WriteError ¶
func WriteError(w http.ResponseWriter, logger *zap.Logger, err error)
WriteError renders err as the standard JSON error envelope.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, payload any)
WriteJSON writes a success payload with Content-Type application/json.
func WriteMethodNotAllowed ¶
func WriteMethodNotAllowed(w http.ResponseWriter, methods ...string)
WriteMethodNotAllowed sets Allow and returns method_not_allowed.
Types ¶
type CursorPayload ¶
type CursorPayload struct {
Offset int `json:"offset"`
}
CursorPayload is the opaque cursor encoding (base64url JSON).
type Error ¶
Error is a safe, typed HTTP error for JSON API responses.