validate

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2022 License: AGPL-3.0 Imports: 12 Imported by: 27

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(ctx context.Context, cname string) []string

CNAME validates given cname

func Email added in v0.6.0

func Email(ctx context.Context, email string) []string

Email validates given email address

func ImageUpload added in v0.15.0

func ImageUpload(ctx context.Context, upload *dto.ImageUpload, opts ImageUploadOpts) ([]string, error)

ImageUpload validates given image upload

func MultiImageUpload added in v0.18.0

func MultiImageUpload(ctx context.Context, currentAttachments []string, uploads []*dto.ImageUpload, opts MultiImageUploadOpts) ([]string, error)

MultiImageUpload validates multiple image uploads

func Subdomain

func Subdomain(ctx context.Context, subdomain string) ([]string, error)

Subdomain validates given subdomain

func URL added in v0.15.0

func URL(ctx context.Context, 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(ctx context.Context, user *entity.User) *Result
	IsAuthorized(ctx context.Context, user *entity.User) 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