api

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ReqIDKey string = "requestID"

Variables

This section is empty.

Functions

func AsErrorResp added in v0.3.1

func AsErrorResp(err error, target **ErrorResp) bool

Helper func for checking if error is of type *ErroResp.

func DefaultErrorHandler added in v0.3.1

func DefaultErrorHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, errResp *ErrorResp)

Can be used in Wrap func as default one

func HTMLErrorHandler added in v0.3.1

func HTMLErrorHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, errResp *ErrorResp)

Default func for html error handling, with examplary html code.

func JSONErrorHandler added in v0.3.1

func JSONErrorHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, errResp *ErrorResp)

Default func for json error handling.

func Wrap added in v0.3.1

A wrapper func for handling errors from the called handler funcs. Uses custom func which handles error response. Defaults to DefaultErrorHandler if nothing is passed.

Types

type ErrorHandlerFunc added in v0.3.1

type ErrorHandlerFunc func(context.Context, http.ResponseWriter, *http.Request, *ErrorResp)

Custom type of error handler func mostly used for custom transport logic.

type ErrorResp

type ErrorResp struct {
	Status    int    `json:"status"`         // HTTP status code with a json tag
	ClientMsg string `json:"client_message"` // Human-readable message with a json tag
	ServerMsg string `json:"-"`              // Server side message, for logging purposes
}

Simple error response struct with json notation.

func FromError added in v0.3.1

func FromError(err error) *ErrorResp

Convertion from error to ErrorResp if possbile.

func NewClientErrorResp added in v0.4.1

func NewClientErrorResp(status int, clientMsg string) *ErrorResp

func NewErrorResp

func NewErrorResp(status int, clientMsg, serverMsg string) *ErrorResp

func (*ErrorResp) Error

func (e *ErrorResp) Error() string

Implementation func of error interface.

type HandlerFunc added in v0.3.1

type HandlerFunc func(context.Context, http.ResponseWriter, *http.Request) *ErrorResp

A handler func which accepts context field and returns error response.

Jump to

Keyboard shortcuts

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