Documentation
¶
Index ¶
- func As(receivedErr error, expectedType any) bool
- func Errorf(ctx context.Context, format string, args ...interface{}) error
- func Is(receivedErr, expectedError error) bool
- func New(ctx context.Context, message string) error
- func Newf(ctx context.Context, format string, args ...interface{}) error
- func RootCtxOrFallback(ctx context.Context, err error) context.Context
- func UnwrapError(err error) error
- func Wrap(ctx context.Context, err error, message string) error
- func Wrapf(ctx context.Context, err error, format string, args ...interface{}) error
- type ErrCtx
- type ValidationErrors
- type ValidationErrorsBuilder
- func (v *ValidationErrorsBuilder) Build() error
- func (v *ValidationErrorsBuilder) Get(field string) []string
- func (v *ValidationErrorsBuilder) Merge(verr *ValidationErrors) *ValidationErrorsBuilder
- func (v *ValidationErrorsBuilder) MergeWithPrefix(prefix string, verr *ValidationErrors) *ValidationErrorsBuilder
- func (v *ValidationErrorsBuilder) Set(field, err string) *ValidationErrorsBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
As checks if any error of the stack matches the expectedType API machting the standard library but allowing to wrap errors with ErrCtx + errgo or pkg/errors
func Is ¶
Is checks if any error of the stack matches the error value expectedError API machting the standard library but allowing to wrap errors with ErrCtx + errgo or pkg/errors
func RootCtxOrFallback ¶
RootCtxOrFallback unwrap all wrapped errors from err to get the deepest context from ErrCtx errors. If there is no wrapped ErrCtx RootCtxOrFallback returns ctx from parameter.
func UnwrapError ¶
UnwrapError tries to unwrap `err`. It unwraps any causer type, errgo and errors implementing Unwrap() method. It returns nil if no err found. This provide the possibility to loop on UnwrapError by checking the return value. E.g.:
for unwrappedErr := err; unwrappedErr != nil; unwrappedErr = UnwrapError(unwrappedErr) {
...
}
Types ¶
type ValidationErrors ¶
ValidationErrors store each errors associated to every fields of a model
func (*ValidationErrors) Error ¶
func (v *ValidationErrors) Error() string
type ValidationErrorsBuilder ¶
type ValidationErrorsBuilder struct {
// contains filtered or unexported fields
}
ValidationErrorsBuilder is used to provide a simple way to create a ValidationErrors struct. The typical usecase is:
func (m *MyModel) Validate(ctx context.Context) *ValidationErrors {
validations := document.NewValidationErrorsBuilder()
if m.Name == "" {
validations.Set("name", "should not be empty")
}
if m.Email == "" {
validations.Set("email", "should not be empty")
}
return validations.Build()
}
func NewValidationErrorsBuilder ¶
func NewValidationErrorsBuilder() *ValidationErrorsBuilder
NewValidationErrors return an empty ValidationErrors struct
func (*ValidationErrorsBuilder) Build ¶
func (v *ValidationErrorsBuilder) Build() error
Build will send a ValidationErrors struct if there is some errors or nil if no errors has been defined
func (*ValidationErrorsBuilder) Get ¶
func (v *ValidationErrorsBuilder) Get(field string) []string
Get will return all errors set for a specific field
func (*ValidationErrorsBuilder) Merge ¶
func (v *ValidationErrorsBuilder) Merge(verr *ValidationErrors) *ValidationErrorsBuilder
Merge ValidationErrors with another ValidationErrors
func (*ValidationErrorsBuilder) MergeWithPrefix ¶
func (v *ValidationErrorsBuilder) MergeWithPrefix(prefix string, verr *ValidationErrors) *ValidationErrorsBuilder
MergeWithPrefix is merging ValidationErrors in another ValidationError adding a prefix for each error field
func (*ValidationErrorsBuilder) Set ¶
func (v *ValidationErrorsBuilder) Set(field, err string) *ValidationErrorsBuilder
Set will add an error on a specific field, if the field already contains an error, it will just add it to the current errors list