vFile

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

File Validators

Index

Constants

View Source
const (
	Type = "file"

	MandatoryErrorFormat  = "File is required."
	AcceptMimeErrorFormat = "Invalid Type, must be '{{.mimes|join \"or\"}}'."
	MaxSizeErrorFormat    = "File size should not be bigger than {{.maxBytes}}."
)

Variables

This section is empty.

Functions

func Must

func Must(file *multipart.FileHeader, err error) *multipart.FileHeader

func MustMultiple

func MustMultiple(files []*multipart.FileHeader, err error) []*multipart.FileHeader

func Validate

func Validate(file *multipart.FileHeader, rules ...ValidationRule) (*multipart.FileHeader, error)

func ValidateMultiple

func ValidateMultiple(files []*multipart.FileHeader, rules ...ValidationRule) ([]*multipart.FileHeader, error)

Types

type ValidationRule

type ValidationRule func(value *multipart.FileHeader, hasError bool) error

func AcceptMime

func AcceptMime(mimes ...string) ValidationRule

Validate Content Type by list of mime

func Mandatory

func Mandatory() ValidationRule

Make sure value is set, if not set the rule return a validation error

func MaxSize

func MaxSize(maxBytes int64) ValidationRule

Validate date by file size.

func Optional

func Optional(rules ...ValidationRule) ValidationRule

Optional Value, if value is not set, return nil, otherwise go though the validation rules.

func OverrideErrorMsg

func OverrideErrorMsg(validationError vError.ValidationError, rules ...ValidationRule) ValidationRule

Override Error Message

Jump to

Keyboard shortcuts

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