response

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package response provides standardised JSON envelope types for REST APIs consumed by frontend clients (React, Vue, Angular, etc.).

All responses share a consistent shape so the frontend can handle them generically without per-endpoint parsing logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Created

func Created[T any](w http.ResponseWriter, data T)

Created writes a 201 JSON envelope around data.

func NoContent

func NoContent(w http.ResponseWriter)

NoContent writes a 204 with no body.

func OK

func OK[T any](w http.ResponseWriter, data T)

OK writes a 200 JSON envelope around data.

func Paginated

func Paginated[T any](w http.ResponseWriter, data []T, page, perPage, total int)

Paginated writes a 200 paginated list response.

Types

type Envelope

type Envelope[T any] struct {
	Data T     `json:"data"`
	Meta *Meta `json:"meta,omitempty"`
}

Envelope is the standard success wrapper for single-resource responses.

{ "data": <T>, "meta": { ... } }

type Meta

type Meta struct {
	RequestID string `json:"request_id,omitempty"`
	Version   string `json:"version,omitempty"`
}

Meta holds optional response metadata (e.g. request ID, version).

type Page

type Page[T any] struct {
	Data       []T        `json:"data"`
	Pagination Pagination `json:"pagination"`
}

Page is the standard wrapper for paginated list responses.

{ "data": [...], "pagination": { "page": 1, "per_page": 20, "total": 100, "total_pages": 5 } }

type Pagination

type Pagination struct {
	Page       int `json:"page"`
	PerPage    int `json:"per_page"`
	Total      int `json:"total"`
	TotalPages int `json:"total_pages"`
}

Pagination holds cursor/offset pagination metadata.

Jump to

Keyboard shortcuts

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