response

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddErrorMessage added in v0.2.0

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

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

func Error

func Error(c echo.Context, options ...AppOpt) error

Error return echo framework json response with standard error response as the structure.

func ErrorCode

func ErrorCode(c echo.Context, code int, options ...AppOpt) error

ErrorCode return echo framework json response with standard error response as the structure and use given code as response status code.

func NewStd added in v0.2.0

func NewStd(code, msg string) error

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

func NewStdErr added in v0.2.0

func NewStdErr(code string, err error) error

NewStdErr init new Std by given code and err Error as the value.

func NewValidationErrors added in v0.2.0

func NewValidationErrors(validations validator.ValidationErrors) []validationError

NewValidationErrors return ready to display error validations.

func Success

func Success(c echo.Context, options ...AppOpt) error

Success return json response with standard success response as the structure.

Types

type App added in v0.2.0

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

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

type AppOpt added in v0.2.0

type AppOpt func(*App)

AppOpt an option signature for App response.

func WithData added in v0.2.0

func WithData(data any) AppOpt

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

func WithErr added in v0.2.0

func WithErr(err error) AppOpt

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

func WithPaginate added in v0.2.0

func WithPaginate(paginate any) AppOpt

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

type Std added in v0.2.0

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 (Std) Error added in v0.2.0

func (e Std) Error() string

Error method that implement error interface.

func (Std) String added in v0.2.0

func (e Std) String() string

String method that implement Stringer interface.

Jump to

Keyboard shortcuts

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