validate

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2019 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const MaxDimensionSize = 1500

MaxDimensionSize is the max width/height of an image. If image is bigger than this, it'll be resized.

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, opts ImageUploadOpts) ([]string, error)

ImageUpload validates given image upload

func MultiImageUpload added in v0.18.0

func MultiImageUpload(currentAttachments []string, uploads []*models.ImageUpload, opts MultiImageUploadOpts) ([]string, error)

MultiImageUpload validates multiple image uploads

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 ImageUploadOpts added in v0.18.0

type ImageUploadOpts struct {
	IsRequired   bool
	MinWidth     int
	MinHeight    int
	ExactRatio   bool
	MaxKilobytes int
}

ImageUploadOpts arguments to validate given upload

type MultiImageUploadOpts added in v0.18.0

type MultiImageUploadOpts struct {
	MaxUploads   int
	IsRequired   bool
	MinWidth     int
	MinHeight    int
	ExactRatio   bool
	MaxKilobytes int
}

MultiImageUploadOpts arguments to validate mulitple image upload process

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