validation

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 3 Imported by: 130

README

strongo-validation

Validation errors & helpers.

Purpose of this class to define a generic set of validation errors.

  • Validation error
    • Bad request
      • Missing field
      • Invalid field value
    • Bad record
      • Missing field
      • Invalid field value
    • Bad field
      • Missing field
      • Invalid field value

You can check if an err error is a validation error or a specific validation error with next functions:

  • IsValidationError(err error) bool
  • IsBadRequestError(err error) bool
  • IsBadRecordError(err error) bool
  • IsBadFieldValueError(err error) bool

Documentation

https://pkg.go.dev/github.com/strongo/validation

Usage

This package is known to be used in next open source projects:

Please submit a pull request to add your project here if you use this package in an open source project.

Versioning

The version is auto-incremented by CI/CD pipeline on push to main branch.

LICENSE

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBadFieldValueError

func IsBadFieldValueError(err error) bool

func IsBadRecordError

func IsBadRecordError(err error) bool

IsBadRecordError checks if provided errors is a validation error

func IsBadRequestError

func IsBadRequestError(err error) bool

IsBadRequestError checks if provided errors is a validation error

func IsValidationError

func IsValidationError(err error) bool

IsValidationError checks if provided errors is a validation error

func MustBeFieldError

func MustBeFieldError(t interface {
	Helper()
	Errorf(format string, args ...interface{})
}, err error, field string)

MustBeFieldError makes sure the provided error is a field error

func NewBadRequestError

func NewBadRequestError(err error) error

NewBadRequestError create error

func NewErrRequestIsMissingRequiredField

func NewErrRequestIsMissingRequiredField(field string) error

NewErrRequestIsMissingRequiredField creates an error for a missing required field in a request

func NewValidationError

func NewValidationError(message string) error

NewValidationError creates a common validation error

Types

type ErrBadFieldValue

type ErrBadFieldValue struct {
	Field   string `json:"field"`
	Message string `json:"message"`
	// contains filtered or unexported fields
}

ErrBadFieldValue reports error for a bad field value

func NewErrBadRecordFieldValue

func NewErrBadRecordFieldValue(field, message string) ErrBadFieldValue

NewErrBadRecordFieldValue creates an error for a bad record field value

func NewErrBadRequestFieldValue

func NewErrBadRequestFieldValue(field, message string) ErrBadFieldValue

NewErrBadRequestFieldValue creates an error for a bad request field value

func NewErrRecordIsMissingRequiredField

func NewErrRecordIsMissingRequiredField(field string) ErrBadFieldValue

NewErrRecordIsMissingRequiredField creates an error for a missing required field in a record

func (ErrBadFieldValue) Error

func (v ErrBadFieldValue) Error() string

func (ErrBadFieldValue) Unwrap

func (v ErrBadFieldValue) Unwrap() error

Jump to

Keyboard shortcuts

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