validation

package
v0.0.0-...-062e030 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddErrorsFromInput

func AddErrorsFromInput(input interface{}, ea *ErrorAdder)

AddErrorsFromInput takes an input struct and adds validation errores using the ErrorAdder

func UnmarshalJSONAndAddErrors

func UnmarshalJSONAndAddErrors(input interface{}, body io.ReadCloser, ea *ErrorAdder)

UnmarshalJSONAndAddErrors turns the JSON into a struct and adds relevant validation errors, including syntax errors

Types

type ErrorAdder

type ErrorAdder struct {
	Errors *[]ErrorMessage
}

ErrorAdder is a struct used to add and write relevant request errors

func NewErrorAdder

func NewErrorAdder() ErrorAdder

NewErrorAdder creates a new ErrorAdder

func (ErrorAdder) Add

func (ea ErrorAdder) Add(errorMessage ErrorMessage)

Add adds a new ErrorMessage to the ErrorAdder

func (ErrorAdder) Flush

func (ea ErrorAdder) Flush(w http.ResponseWriter, httpStatus int)

Flush writes all the current errors in the ErrorAdder, and sets a relevant http status

func (ErrorAdder) HasErrors

func (ea ErrorAdder) HasErrors() bool

HasErrors checks whether there are any errors in the ErrorAdder

type ErrorMessage

type ErrorMessage struct {
	Case    string
	Field   string
	Message string
}

ErrorMessage represents one error to be returned to the user

Jump to

Keyboard shortcuts

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