response

package
v0.0.0-...-5ed4770 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package response provides one-liner constructors for HTTP/WebSocket standard responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(id string, err *errcode.Error) *protocol.Response

Error returns an error Response with code and message from the errcode.Error.

func OK

func OK(id string, payload any) (*protocol.Response, error)

OK returns a success Response with code 0 and the given payload. Returns an error if marshaling fails.

func Paginated

func Paginated(id string, page PageResult) (*protocol.Response, error)

Paginated returns a success Response wrapping a PageResult in the payload. Returns an error if marshaling fails.

func Updates

func Updates(id string, updates []protocol.Update) *protocol.Response

Updates returns a success Response carrying a list of Update entries.

func WriteResponse

func WriteResponse(w http.ResponseWriter, resp *protocol.Response, err *errcode.Error)

WriteResponse writes a protocol.Response as JSON to the http.ResponseWriter with the appropriate HTTP status code.

Types

type PageResult

type PageResult struct {
	Items   any   `json:"items"`
	Total   int64 `json:"total"`
	Page    int   `json:"page"`
	Size    int   `json:"size"`
	HasMore bool  `json:"has_more"`
}

PageResult holds pagination data for list endpoints.

func PageData

func PageData(items any, total int64, page, size int, hasMore bool) PageResult

PageData constructs a PageResult with sane defaults for invalid inputs.

Jump to

Keyboard shortcuts

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