response

package
v0.0.0-...-c2300e3 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package response provides the response and error handling types support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsError

func IsError(err error) bool

IsError checks if an error of type Error exists.

func NewError

func NewError(err error, status int) error

NewError wraps a provided error with an HTTP status code. This function should be used when handlers encounter expected errors.

Types

type Error

type Error struct {
	Err    error
	Status int
}

Error is used to pass an error during the request through the application with web specific context.

func GetError

func GetError(err error) *Error

GetError returns a copy of the Error pointer.

func (*Error) Error

func (re *Error) Error() string

Error implements the error interface. It uses the default message of the wrapped error. This is what will be shown in the services' logs.

type ErrorDocument

type ErrorDocument struct {
	Error  string            `json:"error"`
	Fields map[string]string `json:"fields,omitempty"`
}

ErrorDocument is the form used for API responses from failures in the API.

type PageDocument

type PageDocument[T any] struct {
	Items       []T `json:"items"`
	Total       int `json:"total"`
	Page        int `json:"page"`
	RowsPerPage int `json:"rowsPerPage"`
}

PageDocument is the form used for API responses from query API calls.

func NewPageDocument

func NewPageDocument[T any](items []T, total int, page int, rowsPrePage int) PageDocument[T]

NewPageDocument constructs a response value for a web paging response.

Jump to

Keyboard shortcuts

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