validate

package
Version: v0.0.0-...-b472bfd Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package validate contains the support for validating models.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidID = errors.New("ID is not in its proper form")

ErrInvalidID occurs when an ID is not in a valid form.

Functions

func Check

func Check(val interface{}) error

Check validates the provided model against it's declared tags.

func CheckID

func CheckID(id string) error

CheckID validates that the format of an id is valid.

func GenerateID

func GenerateID() string

GenerateID generate a unique id for entities.

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.

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.

type FieldErrors

type FieldErrors []FieldError

FieldErrors represents a collection of field errors.

func (FieldErrors) Error

func (fe FieldErrors) Error() string

Error implments the error interface.

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

Error implements the error interface. It uses the default message of the wrapped error. This is what will be shown in the services' logs.

Jump to

Keyboard shortcuts

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