https://github.com/containerum/cherry
https://github.com/containerum/cherry
platform
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/containerum/cherry
- Owner: containerum
- License: apache-2.0
- Created: 2018-04-27T09:16:22.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-01T08:53:29.000Z (almost 8 years ago)
- Last Synced: 2025-04-09T18:44:53.578Z (about 1 year ago)
- Topics: platform
- Language: Go
- Size: 3.09 MB
- Stars: 2
- Watchers: 9
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
```go
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"
```go
func BuildErr(prefix string) func(string, int, string) *Err
```
BuildErr -- produces Err constructor with custom ID prefix Example:
```go
MyErr := BuildErr("42")
ErrNotEnoughCheese = MyErr("not enough cheese", 404, "666")
```
--> "[42666] HTTP 400 not enough cheese "
```go
func NewErr(msg string, status int, ID string) *Err
```
NewErr -- constructs Err struct with provided message and ID
```go
func (err *Err) AddDetailF(formatS string, args ...interface{}) *Err
```
AddDetailF --adds formatted message to Err, chainable
```go
func (err *Err) AddDetails(details ...string) *Err
```
AddDetails -- adds detail messages to Err, chainable
```go
func (err *Err) AddDetailsErr(details ...error) *Err
```
AddDetailsErr -- adds errors as detail messages to Err,chainable
```go
func (err *Err) WithField(name, value string) *Err
```
WithField -- adds field to Err, chainable
```go
func (err *Err) WithFields(fields Fields) *Err
```
WithFields -- adds fields to Err, chainable
```go
func (err *Err) Error() string
```
Returns text representation kinda "unable to parse quota []"
```go
func (err *Err) Gonic(ctx *gin.Context)
```
Gonic -- aborts gin HTTP request with StatusHTTP and provides json representation of error