validate

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CNAME added in v0.8.0

func CNAME(tenants storage.Tenant, cname string) []string

CNAME validates given cname

func Email added in v0.6.0

func Email(email string) []string

Email validates given email address

func ImageUpload added in v0.15.0

func ImageUpload(upload *models.ImageUpload, minWidth, minHeight, maxKilobytes int) ([]string, error)

ImageUpload validates given image upload

func Subdomain

func Subdomain(tenants storage.Tenant, subdomain string) ([]string, error)

Subdomain validates given subdomain

func URL added in v0.15.0

func URL(rawurl string) []string

URL validates given URL

Types

type ErrorItem added in v0.15.0

type ErrorItem struct {
	Field   string `json:"field,omitempty"`
	Message string `json:"message"`
}

ErrorItem holds a reference to something that went wrong

type Result

type Result struct {
	Ok         bool
	Authorized bool
	Err        error
	Errors     []ErrorItem
}

Result is returned after each validation

func Error

func Error(err error) *Result

Error returns a failed validation result

func Failed

func Failed(messages ...string) *Result

Failed returns a failed validation result

func Success

func Success() *Result

Success returns a successful validation

func Unauthorized

func Unauthorized() *Result

Unauthorized returns an unauthorized validation result

func (*Result) AddFieldFailure

func (r *Result) AddFieldFailure(field string, messages ...string)

AddFieldFailure add failure message to specific field

type Validatable

type Validatable interface {
	Validate(user *models.User, services *app.Services) *Result
	IsAuthorized(user *models.User, services *app.Services) bool
}

Validatable defines which models can be validated against context

Jump to

Keyboard shortcuts

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