utils

package
v1.2.3-testnet Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2019 License: ISC Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasDBError

func HasDBError(dbErrors []error) bool

HasDBError returns true if the given dbErrors contain any errors that aren't RecordNotFound

func IsDBRecordNotFoundError

func IsDBRecordNotFoundError(dbErrors []error) bool

IsDBRecordNotFoundError returns true if the given dbErrors contains only a RecordNotFound error

func NewErrorFromDBErrors

func NewErrorFromDBErrors(prefix string, dbErrors []error) error

NewErrorFromDBErrors takes a slice of database errors and a prefix, and returns an error with all of the database errors formatted to one string with the given prefix

Types

type APIServerContext

type APIServerContext struct {
	context.Context
}

APIServerContext is a context.Context wrapper that enables custom logs with request ID.

func ToAPIServerContext

func ToAPIServerContext(ctx context.Context) *APIServerContext

ToAPIServerContext takes a context.Context instance and converts it to *ApiServerContext.

func (*APIServerContext) Criticalf

func (ctx *APIServerContext) Criticalf(format string, params ...interface{})

Criticalf writes a customized formatted context related log with log level 'Critical'.

func (*APIServerContext) Debugf

func (ctx *APIServerContext) Debugf(format string, params ...interface{})

Debugf writes a customized formatted context related log with log level 'Debug'.

func (*APIServerContext) Errorf

func (ctx *APIServerContext) Errorf(format string, params ...interface{})

Errorf writes a customized formatted context related log with log level 'Error'.

func (*APIServerContext) Infof

func (ctx *APIServerContext) Infof(format string, params ...interface{})

Infof writes a customized formatted context related log with log level 'Info'.

func (*APIServerContext) SetRequestID

func (ctx *APIServerContext) SetRequestID(requestID uint64) context.Context

SetRequestID associates a request ID for the context.

func (*APIServerContext) Tracef

func (ctx *APIServerContext) Tracef(format string, params ...interface{})

Tracef writes a customized formatted context related log with log level 'Trace'.

func (*APIServerContext) Warnf

func (ctx *APIServerContext) Warnf(format string, params ...interface{})

Warnf writes a customized formatted context related log with log level 'Warn'.

type HandlerError

type HandlerError struct {
	Code          int
	Message       string
	ClientMessage string
}

HandlerError is an error returned from a rest route handler or a middleware.

func NewHandlerError

func NewHandlerError(code int, message string) *HandlerError

NewHandlerError returns a HandlerError with the given code and message.

func NewHandlerErrorFromDBErrors

func NewHandlerErrorFromDBErrors(prefix string, dbErrors []error) *HandlerError

NewHandlerErrorFromDBErrors takes a slice of database errors and a prefix, and returns an HandlerError with error code http.StatusInternalServerError with all of the database errors formatted to one string with the given prefix

func NewHandlerErrorWithCustomClientMessage

func NewHandlerErrorWithCustomClientMessage(code int, message, clientMessage string) *HandlerError

NewHandlerErrorWithCustomClientMessage returns a HandlerError with the given code, message and client error message.

func NewInternalServerHandlerError

func NewInternalServerHandlerError(message string) *HandlerError

NewInternalServerHandlerError returns a HandlerError with the given message, and the http.StatusInternalServerError status text as client message.

func (*HandlerError) Error

func (hErr *HandlerError) Error() string

Jump to

Keyboard shortcuts

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