validate

package
v0.0.0-...-acda5ee Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: GPL-3.0 Imports: 12 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

func CNAME(ctx context.Context, cname string) []string

CNAME validates given cname

func Email

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

Email validates given email address

func ImageUpload

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

ImageUpload validates given image upload

func MultiImageUpload

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

func URL(ctx context.Context, rawurl string) []string

URL validates given URL

Types

type ErrorItem

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

ErrorItem holds a reference to something that went wrong

type ImageUploadOpts

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

ImageUploadOpts arguments to validate given upload

type MultiImageUploadOpts

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