-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca0ae8a
commit 21a020e
Showing
46 changed files
with
832 additions
and
1,278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package config | ||
|
||
const ( | ||
DefaultFendDelimiter = ";" | ||
DefaultFendNameDelimiter = ":" | ||
DefaultRuleDelimiter = ":" | ||
DefaultRuleMetaDelimiter = "=" | ||
) | ||
|
||
var ( | ||
FendDelimiter = DefaultFendDelimiter | ||
FendNameDelimiter = DefaultFendNameDelimiter | ||
RuleDelimiter = DefaultRuleDelimiter | ||
RuleMetaDelimiter = DefaultRuleMetaDelimiter | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,51 @@ | ||
package fender | ||
|
||
// Error type | ||
import ( | ||
"errors" | ||
"strings" | ||
|
||
"github.com/foomo/fender/config" | ||
"go.uber.org/multierr" | ||
) | ||
|
||
type Error struct { | ||
Fields FieldErrors | ||
cause error | ||
} | ||
|
||
var Err = &Error{} | ||
|
||
// NewError constructor | ||
func NewError(fields FieldErrors) *Error { | ||
func NewError(cause error) *Error { | ||
return &Error{ | ||
Fields: fields, | ||
cause: cause, | ||
} | ||
} | ||
|
||
// Is interface | ||
func (e *Error) Is(err error) bool { | ||
if err == nil { | ||
return false | ||
func (e *Error) Error() string { | ||
errs := multierr.Errors(e.cause) | ||
causes := make([]string, len(errs)) | ||
for i, cause := range errs { | ||
causes[i] = cause.Error() | ||
} | ||
_, ok := err.(*Error) //nolint:errorlint | ||
return ok | ||
return strings.Join(causes, config.FendDelimiter) | ||
} | ||
|
||
// Error interface | ||
func (e *Error) Error() string { | ||
return e.Fields.String() | ||
func (e *Error) First() error { | ||
if errs := e.Errors(); len(errs) > 0 { | ||
return errs[0] | ||
} | ||
return nil | ||
} | ||
|
||
func (e *Error) Errors() FieldErrors { | ||
return e.Fields | ||
func (e *Error) Errors() []error { | ||
return multierr.Errors(e.cause) | ||
} | ||
|
||
func (e *Error) First() error { | ||
for _, err := range e.Fields { | ||
return err | ||
func (e *Error) Unwrap() error { | ||
return e.cause | ||
} | ||
|
||
func AsError(err error) *Error { | ||
var fendErr *Error | ||
if errors.As(err, &fendErr) { | ||
return fendErr | ||
} | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.