api

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilRequest reports that a helper was called without an HTTP request.
	ErrNilRequest = errors.New("api request is nil")
	// ErrUnsupportedContentType reports a non-JSON request content type.
	ErrUnsupportedContentType = errors.New("unsupported API content type")
	// ErrMultipleJSONValues reports a JSON request body with trailing values.
	ErrMultipleJSONValues = errors.New("multiple JSON values in API request body")
)

Functions

func DecodeJSON

func DecodeJSON[T any](request *http.Request) (T, error)

DecodeJSON decodes a JSON request body into T. Unknown object fields are rejected so handler inputs stay explicit.

func Error

func Error(status int, code string, message string) (response.Response, error)

Error creates a structured JSON API error response.

func JSON

func JSON(status int, value any) (response.Response, error)

JSON creates a runtime response from a value encoded as JSON.

func NoContent

func NoContent() response.Response

NoContent creates an empty successful API response.

func QueryBool

func QueryBool(request *http.Request, name string) (bool, bool, error)

QueryBool returns the first query value for name as a bool.

func QueryInt

func QueryInt(request *http.Request, name string) (int, bool, error)

QueryInt returns the first query value for name as an int.

func QueryInt64

func QueryInt64(request *http.Request, name string) (int64, bool, error)

QueryInt64 returns the first query value for name as an int64.

func QueryString

func QueryString(request *http.Request, name string) (string, bool)

QueryString returns the first query value for name.

func QueryStrings

func QueryStrings(request *http.Request, name string) []string

QueryStrings returns all query values for name.

Types

type ErrorBody

type ErrorBody struct {
	OK    bool      `json:"ok"`
	Error ErrorInfo `json:"error"`
}

ErrorBody is the default structured error payload for API helpers.

type ErrorInfo

type ErrorInfo struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

ErrorInfo describes one API error.

type Handler

type Handler func(http.ResponseWriter, *http.Request)

Handler is a generated API endpoint.

type Registry

type Registry map[string]Handler

Registry maps generated API handler names to handlers.

Jump to

Keyboard shortcuts

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