api

package
v0.6.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const ImportPath = "github.com/cssbruno/gowdk/addons/api"

ImportPath is the canonical Go import path for the API addon.

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 Addon

func Addon() gowdk.Addon

Addon enables generated API handlers.

func DecodeJSON added in v0.5.0

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 added in v0.5.0

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

Error creates a structured JSON API error response.

func JSON added in v0.5.0

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

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

func NoContent added in v0.5.0

func NoContent() response.Response

NoContent creates an empty successful API response.

func QueryBool added in v0.5.0

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

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

func QueryInt added in v0.5.0

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

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

func QueryInt64 added in v0.5.0

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

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

func QueryString added in v0.5.0

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

QueryString returns the first query value for name.

func QueryStrings added in v0.5.0

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

QueryStrings returns all query values for name.

Types

type ErrorBody added in v0.5.0

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

ErrorBody is the default structured error payload for API helpers.

type ErrorInfo added in v0.5.0

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