validator

package
v0.0.0-...-e31cc93 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFileInvalidExtension = errors.New(
	`extension validator: File has an invalid extension type`)

ErrFileInvalidExtension is an error type that is rendered when an extension is shown

View Source
var ErrFileInvalidMimeType = errors.New(`
  mimetype validator: File has an invalid mimetype`)

ErrFileInvalidMimeType is an error type denoting a file with a mimetype unrecognized by the validator

View Source
var ErrFileSizeTooLarge = errors.New(`
	size validator: File size is too large`)

ErrFileSizeTooLarge is an error type for files that signifies a file s too large

View Source
var ErrFileSizeTooSmall = errors.New(`
	size validator: File size is too small`)

ErrFileSizeTooSmall is an error type that denotes a file is too small Thus the reason behind the validation's failure

Functions

This section is empty.

Types

type ChainedValidator

type ChainedValidator struct {
	// contains filtered or unexported fields
}

ChainedValidator is a validator that is composed of other validators It doesn't perform any validation itself instead it defers to the validators it has been composed of

func NewChainedValidator

func NewChainedValidator(v ...Validator) *ChainedValidator

NewChainedValidator returns an instance of a ChainedValidator. It panics if no validator is added to the chain

func (*ChainedValidator) Validate

func (c *ChainedValidator) Validate(f filer.File) (bool, error)

type ExtensionValidator

type ExtensionValidator struct {
	// contains filtered or unexported fields
}

ExtensionValidator is a validator that validates a file based on it's extension Extremely dumb and cannot be trusted

func NewExtensionValidator

func NewExtensionValidator(allowedExtensions []string) *ExtensionValidator

NewExtensionValidator returns an instance of an ExtensionValidator

func (*ExtensionValidator) Validate

func (e *ExtensionValidator) Validate(f filer.File) (bool, error)

Validate checks if a file is valid by looking at it's extension

type MimeTypeValidator

type MimeTypeValidator struct {
	// contains filtered or unexported fields
}

MimeTypeValidator is a validator that checks the mimetype of a file and compares it to a list of acceptable mimetypes to determine wheter it is valid or not

func NewMimeTypeValidator

func NewMimeTypeValidator(mimeTypes []string) *MimeTypeValidator

NewMimeTypeValidator returns an instance of a MimeTypeValidator

func (*MimeTypeValidator) Validate

func (mime *MimeTypeValidator) Validate(f filer.File) (bool, error)

Validate validates a file by looking at it's mimetype. Currrently, the mimetype of the file is gotten by through the DetectContentType function in net/http.

type SizeValidator

type SizeValidator struct {
	// contains filtered or unexported fields
}

SizeValidator is a validator that checks the size of a file to determine if it is valid or not based on predefined criterias

func NewSizeValidator

func NewSizeValidator(maxSize, minSize int64) *SizeValidator

NewSizeValidator returns an instance of a SizeValidator maxSize and minSize are to be given in bytes

func (*SizeValidator) Validate

func (s *SizeValidator) Validate(f filer.File) (bool, error)

Validate validates a file based on it's size

type Validator

type Validator interface {
	Validate(filer.File) (bool, error)
}

Jump to

Keyboard shortcuts

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