cherry

package module
Version: v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

README

type Err struct {
    Message    string            `json:"message"`
    StatusHTTP int               `json:"-"`
    ID         string            `json:"id"`
    Details    []string          `json:"details,omitempty"`
    Fields     map[string]string `json:"fields,omitempty"
}
Err -- standart serializable API error Message -- constant error
message:

+ "invalid username"
+ "quota exceeded"
+ "validation error"
...etc...

ID -- unique error identification code Details -- optional context error
messages kinda

+ "field 'Replicas' must be non-zero value"
+ "not enough tights to feed gopher"
+ "resource 'God' does't exist"
func BuildErr(prefix string) func(string, int, string) *Err

BuildErr -- produces Err constructor with custom ID prefix Example:

	MyErr := BuildErr("42")
	ErrNotEnoughCheese = MyErr("not enough cheese", 404, "666")
    --> "[42666] HTTP 400 not enough cheese "
func NewErr(msg string, status int, ID string) *Err

NewErr -- constructs Err struct with provided message and ID

func (err *Err) AddDetailF(formatS string, args ...interface{}) *Err

AddDetailF --adds formatted message to Err, chainable

func (err *Err) AddDetails(details ...string) *Err

AddDetails -- adds detail messages to Err, chainable

func (err *Err) AddDetailsErr(details ...error) *Err

AddDetailsErr -- adds errors as detail messages to Err,chainable

func (err *Err) WithField(name, value string) *Err

WithField -- adds field to Err, chainable

func (err *Err) WithFields(fields Fields) *Err

WithFields -- adds fields to Err, chainable

func (err *Err) Error() string

Returns text representation kinda "unable to parse quota []"

func (err *Err) Gonic(ctx *gin.Context)

Gonic -- aborts gin HTTP request with StatusHTTP and provides json representation of error

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildErr

func BuildErr(SID ErrSID) func(string, int, ErrKind) *Err

BuildErr -- produces Err constructor with custom ID prefix Example:

	MyErr := BuildErr("serivice_id")
 ErrNotEnoughCheese = MyErr("not enough cheese", "666")
 	--> "not enough cheese [service_id666]"

func Equals

func Equals(err error, other *Err) bool

Equals -- attempts to compare error with cherry error. If error is not *Err returns false. Otherwise uses (*Err).Equals() for comparison.

func In

func In(err error, list ...*Err) bool

In -- determines whether err is in list of cherry errs.

func ProducedByService

func ProducedByService(err error, sid ErrSID) bool

ProducedByService -- determines whether error produced by given service If err is not *Err returns false. Otherwise compares (*Err).ID.SID with sid.

Types

type Err

type Err struct {
	Message    string   `json:"message"`
	StatusHTTP int      `json:"status_http"`
	ID         ErrID    `json:"id"`
	Details    []string `json:"details,omitempty"`
	Fields     Fields   `json:"fields,omitempty"`
}

Err -- standard serializable API error Message -- constant error message:

+ "invalid username"
+ "quota exceeded"
+ "validation error"
...etc...

ID -- unique error identification code Details -- optional context error messages kinda

+ "field 'Replicas' must be non-zero value"
+ "not enough tights to feed gopher"
+ "resource 'God' does't exist"

Fields -- optional set of key-value pairs swagger:model

func NewErr

func NewErr(msg string, status int, ID ErrID) *Err

NewErr -- constructs Err struct with provided message and ID

func WhichOne

func WhichOne(err error, list ...*Err) *Err

WhichOne -- searches err in list of cherry errs. If err is in list returns list item which equals to err. If err is not in list returns nil. Uses (*Err).Equals() for comparison.

func (*Err) AddDetailF

func (err *Err) AddDetailF(formatS string, args ...interface{}) *Err

AddDetailF --adds formatted message to Err, chainable

func (*Err) AddDetails

func (err *Err) AddDetails(details ...string) *Err

AddDetails -- adds detail messages to Err, chainable

func (*Err) AddDetailsErr

func (err *Err) AddDetailsErr(details ...error) *Err

AddDetailsErr -- adds errors as detail messages to Err, chainable

func (*Err) Emit

func (err *Err) Emit() *Err

Emit -- if err is nil, the return initialized error

func (*Err) EmitDefault

func (err *Err) EmitDefault(defaulterr Err) *Err

func (*Err) Equals

func (err *Err) Equals(other *Err) bool

Equals -- compares with other cherry error. Two cherry errors equal if IDs are deep equal (Kind and SID are equal).

func (*Err) Error

func (err *Err) Error() string

Returns text representation kinda "unable to parse quota []"

func (*Err) Log

func (err *Err) Log(origin error, logger ErrorLogger) *Err

Log -- logs origin error for returning error using ErrLogger, Chainable.

func (*Err) WithField

func (err *Err) WithField(name, value string) *Err

WithField -- adds field to Err, chainable

func (*Err) WithFields

func (err *Err) WithFields(fields Fields) *Err

WithFields -- adds fields to Err, chainable

type ErrConstruct

type ErrConstruct func(...func(*Err)) *Err

func (ErrConstruct) AddDetailF

func (constr ErrConstruct) AddDetailF(f string, vals ...interface{}) ErrConstruct

func (ErrConstruct) AddDetails

func (constr ErrConstruct) AddDetails(details ...string) ErrConstruct

func (ErrConstruct) AddDetailsErr

func (constr ErrConstruct) AddDetailsErr(details ...error) ErrConstruct

func (ErrConstruct) Error

func (constr ErrConstruct) Error() string

func (ErrConstruct) WithField

func (constr ErrConstruct) WithField(key, value string) ErrConstruct

func (ErrConstruct) WithFields

func (constr ErrConstruct) WithFields(fields Fields) ErrConstruct

type ErrID

type ErrID struct {
	SID  ErrSID  `json:"sid"`
	Kind ErrKind `json:"kind"`
}

ErrID -- represents unique error ID

func (*ErrID) String

func (errID *ErrID) String() string

type ErrKind

type ErrKind uint64

ErrKind -- represents kind of error

type ErrSID

type ErrSID string

ErrSID -- represents service ID of error

type ErrorLogger

type ErrorLogger interface {
	Log(origin error, returning *Err)
}

ErrLogger -- interface for logging origin and returned errors due to origin errors discarding

type Fields

type Fields map[string]string

Fields -- represents additional key-value fields of error

Directories

Path Synopsis
adaptors
cmd
exampleErrors
Code generated by noice.
Code generated by noice.
pkg

Jump to

Keyboard shortcuts

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