response

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(w http.ResponseWriter, statusCode int, code, message string, details any)

Error sends an error response with structured error info

func SendJSON

func SendJSON(w http.ResponseWriter, statusCode int, resp Response)

SendJSON sends a JSON response with the given status code

func Success

func Success(w http.ResponseWriter, data any)

Success sends a successful response with data

func SuccessList

func SuccessList(w http.ResponseWriter, items any, meta any)

SuccessList sends a list response whose Data is never omitted (so empty lists render as "data":[]) and whose optional Meta carries pagination. Use this for the agent v1 list endpoints instead of Success (see listResponse for the omitempty rationale).

Types

type ErrorInfo

type ErrorInfo struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Details any    `json:"details,omitempty"`
}

ErrorInfo represents structured error information

type ListMeta

type ListMeta struct {
	Pagination Pagination `json:"pagination"`
}

ListMeta wraps pagination metadata under the canonical "pagination" key.

type Pagination

type Pagination struct {
	NextCursor string `json:"nextCursor,omitempty"`
	HasMore    bool   `json:"hasMore"`
	// Total is the number of items matching the current filters, regardless of the
	// page. Populated only by offset-paginated endpoints.
	Total *int `json:"total,omitempty"`
	// Limit and Offset echo the page parameters the client requested. Populated only
	// by offset-paginated endpoints.
	Limit  *int `json:"limit,omitempty"`
	Offset *int `json:"offset,omitempty"`
}

Pagination is the list-pagination metadata carried in a list response's meta. It is generic so the media list (Story 2.3) reuses the same envelope. Two pagination models share this struct: cursor endpoints populate NextCursor (keyset, stable under concurrent inserts/deletes), while offset endpoints populate Total/Limit/Offset so clients know how many items match the current filters.

type Response

type Response struct {
	Data  any `json:"data,omitempty"`
	Error any `json:"error,omitempty"`
	Meta  any `json:"meta,omitempty"`
}

Response represents a uniform JSON response structure

Jump to

Keyboard shortcuts

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