httpresp

package
v0.0.0-...-1f1dc5f Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package httpresp renders framework-specific HTTP error responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIError

func APIError(c *echo.Context, err error) error

APIError renders a project error as a JSON HTTP response.

func Created

func Created(c *echo.Context, data interface{}) error

Created renders a successful creation response envelope.

func List

func List(c *echo.Context, data interface{}, page PageMeta) error

List renders a successful paginated list response envelope.

func OK

func OK(c *echo.Context, data interface{}) error

OK renders a successful response envelope.

func RequestID

func RequestID(c *echo.Context) string

RequestID returns the request ID used in HTTP error responses.

func Status

func Status(kind apperr.Kind) int

Status maps framework-free application error kinds to HTTP status codes.

Types

type ErrorResponse

type ErrorResponse struct {
	Code      int    `json:"code"`
	Message   string `json:"message"`
	RequestID string `json:"request_id"`
	Timestamp int64  `json:"timestamp"`
}

ErrorResponse is the standard JSON error response for HTTP adapters.

type ListResponse

type ListResponse struct {
	Code      int         `json:"code"`
	Message   string      `json:"message"`
	Data      interface{} `json:"data"`
	Page      PageMeta    `json:"page"`
	RequestID string      `json:"request_id"`
	Timestamp int64       `json:"timestamp"`
}

ListResponse is the standard JSON list response for HTTP adapters.

type PageMeta

type PageMeta struct {
	Page     int  `json:"page"`
	PageSize int  `json:"page_size"`
	Total    int  `json:"total"`
	HasNext  bool `json:"has_next"`
}

PageMeta describes paginated list response metadata.

func NewPageMeta

func NewPageMeta(page, pageSize, total int) (PageMeta, error)

NewPageMeta validates and creates pagination metadata.

type Response

type Response struct {
	Code      int         `json:"code"`
	Message   string      `json:"message"`
	Data      interface{} `json:"data,omitempty"`
	RequestID string      `json:"request_id"`
	Timestamp int64       `json:"timestamp"`
}

Response is the standard JSON success response for HTTP adapters.

Jump to

Keyboard shortcuts

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