response

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddErrorMessage

func AddErrorMessage(k string, v func(validator.FieldError) string)

AddErrorMessage add or replace error message mapping to bag from given key value.

func NewValidationErrors

func NewValidationErrors(validations validator.ValidationErrors) []validationError

NewValidationErrors return ready to display error validations.

Types

type AppError

type AppError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Error   any    `json:"error,omitempty"`
}

AppError standard error response that may be used in every response for all handlers.

type AppErrorOption

type AppErrorOption func(*AppError)

AppErrorOption an option for AppError response.

func WithErr

func WithErr(err error) AppErrorOption

WithErr option to add given detail to error response as `error` field.

type AppSuccess

type AppSuccess struct {
	Message    string `json:"message"`
	Data       any    `json:"data,omitempty"`
	Pagination any    `json:"pagination,omitempty"` // Pagination additional field when need to serve many Data and want to show pagination info.
}

AppSuccess standard success response that may be used in every response for all handlers.

type AppSuccessOption

type AppSuccessOption func(*AppSuccess)

AppSuccessOption an option for AppSuccess response.

func WithData

func WithData(data any) AppSuccessOption

WithData option to add the given data to success response as `data` field.

func WithPaginate

func WithPaginate(paginate any) AppSuccessOption

WithPaginate option to add the given paginate to success response as `pagination` field.

type Std

type Std struct {
	Code    string
	Message string
}

Std error implementer that may be used when need to throw just code and message as response inside `error` field.

func NewStd

func NewStd(code, msg string) *Std

NewStd init new Std by given code and message as the value.

func (Std) Error

func (e Std) Error() string

Error method that implement error interface.

func (Std) String

func (e Std) String() string

String method that implement Stringer interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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