validate

package
v0.0.0-...-6fd8457 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package validate provides a wrapper around the go-playground/validator package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cause

func Cause(err error) error

Cause iterates through all the wrapped errors until the root error value is reached.

func Check

func Check(val any) error

Check a struct for validation errors and returns any errors the occur. This wraps the validate.Struct() function and provides some error wrapping. When a validator.ValidationErrors is returned, it is wrapped transformed into a FieldErrors array and returned.

func IsFieldError

func IsFieldError(err error) bool

func IsInvalidRouteKeyError

func IsInvalidRouteKeyError(err error) bool

func IsRequestError

func IsRequestError(err error) bool

IsRequestError checks if an error of type RequestError exists.

func IsUnauthorizedError

func IsUnauthorizedError(err error) bool

func NewRequestError

func NewRequestError(err error, status int) error

NewRequestError wraps a provided error with an HTTP status code. This function should be used when handlers encounter expected errors.

func NewRouteKeyError

func NewRouteKeyError(key string) error

func NewUnauthorizedError

func NewUnauthorizedError() error

Types

type ErrorResponse

type ErrorResponse struct {
	Error  string `json:"error"`
	Fields string `json:"fields,omitempty"`
}

ErrorResponse is the form used for API responses from failures in the API.

type FieldError

type FieldError struct {
	Field string `json:"field"`
	Error string `json:"error"`
}

FieldError is used to indicate an error with a specific request field.

func NewFieldError

func NewFieldError(field, reason string) FieldError

type FieldErrors

type FieldErrors []FieldError

FieldErrors represents a collection of field errors.

func NewFieldErrors

func NewFieldErrors(errs ...FieldError) FieldErrors

func (FieldErrors) Append

func (fe FieldErrors) Append(field, reason string) FieldErrors

func (FieldErrors) Error

func (fe FieldErrors) Error() string

Error implements the error interface.

func (FieldErrors) Nil

func (fe FieldErrors) Nil() bool

type InvalidRouteKeyError

type InvalidRouteKeyError struct {
	// contains filtered or unexported fields
}

func (*InvalidRouteKeyError) Error

func (err *InvalidRouteKeyError) Error() string

type RequestError

type RequestError struct {
	Err    error
	Status int
	Fields error
}

RequestError is used to pass an error during the request through the application with web specific context.

func (*RequestError) Error

func (err *RequestError) Error() string

type UnauthorizedError

type UnauthorizedError struct {
}

func (*UnauthorizedError) Error

func (err *UnauthorizedError) Error() string

Jump to

Keyboard shortcuts

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