response

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeNotFound      = "NOT_FOUND"
	CodeInternalError = "INTERNAL_ERROR"
	CodeInvalidJSON   = "INVALID_JSON"
	CodeUnknownField  = "UNKNOWN_FIELD"
	CodeBodyTooLarge  = "BODY_TOO_LARGE"
	// CodeExportTooLarge is used with HTTP 413 when a requested export exceeds
	// the server's row cap. Distinct from CodeBodyTooLarge, which is about the
	// request body.
	CodeExportTooLarge     = "EXPORT_TOO_LARGE"
	CodeValidationError    = "VALIDATION_ERROR"
	CodeConflict           = "CONFLICT"
	CodeUnauthorized       = "UNAUTHORIZED"
	CodeForbidden          = "FORBIDDEN"
	CodeRateLimited        = "RATE_LIMITED"
	CodeAuthzError         = "AUTHZ_ERROR"
	CodeServiceUnavailable = "SERVICE_UNAVAILABLE"
)

Standard error codes for API responses. Modules do NOT define their own codes — business errors are distinguished by the message field, not the code.

Variables

This section is empty.

Functions

func Error

func Error(w http.ResponseWriter, r *http.Request, status int, code, message string)

func JSON

func JSON(w http.ResponseWriter, status int, data any)

func JSONFail

func JSONFail(w http.ResponseWriter, status int, message string, data any)

func JSONList

func JSONList(w http.ResponseWriter, status int, items any, total, limit, offset int)

JSONList writes a paginated list response.

func JSONListWithMeta

func JSONListWithMeta(w http.ResponseWriter, status int, items any, meta any)

JSONListWithMeta writes a paginated list response with a custom meta object.

func JSONWithMessage

func JSONWithMessage(w http.ResponseWriter, status int, message string, data any)

func ValidationError

func ValidationError(w http.ResponseWriter, r *http.Request, fields map[string]string)

ValidationError sends a 400 response containing per-field validation errors.

Types

type ErrorResponse

type ErrorResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Code    string `json:"code"`
	TraceID string `json:"trace_id,omitempty"`

} //	@name	ErrorResponse

ErrorResponse is the standard error envelope for API responses.

type ListMeta

type ListMeta struct {
	Total  int `json:"total"`
	Limit  int `json:"limit"`
	Offset int `json:"offset"`

} //	@name	ListMeta

ListMeta contains pagination metadata for list responses.

type ListResponse

type ListResponse struct {
	Success bool     `json:"success"`
	Message string   `json:"message"`
	Data    any      `json:"data"`
	Meta    ListMeta `json:"meta"`

} //	@name	ListResponse

ListResponse is the envelope for paginated list endpoints.

type SuccessResponse

type SuccessResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Data    any    `json:"data"`

} //	@name	SuccessResponse

SuccessResponse is the standard success envelope for API responses.

type ValidationErrorResponse

type ValidationErrorResponse struct {
	Success bool              `json:"success"`
	Message string            `json:"message"`
	Code    string            `json:"code"`
	Fields  map[string]string `json:"fields"`

} //	@name	ValidationErrorResponse

ValidationErrorResponse is a 400 response with per-field errors.

Jump to

Keyboard shortcuts

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