validators

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 16 Imported by: 17

Documentation

Overview

Package validators implements custom shared PocketBase validators.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(valueToCompare string) validation.RuleFunc

Compare checks whether the validated value matches another string.

Example:

validation.Field(&form.PasswordConfirm, validation.By(validators.Compare(form.Password)))

func UniqueId added in v0.12.0

func UniqueId(dao *daos.Dao, tableName string) validation.RuleFunc

Compare checks whether the provided model id exists.

Example:

validation.Field(&form.Id, validation.By(validators.UniqueId(form.dao, tableName)))

func UploadedFileMimeType

func UploadedFileMimeType(validTypes []string) validation.RuleFunc

UploadedFileMimeType checks whether the validated `rest.UploadedFile` mimetype is within the provided allowed mime types.

Example:

validMimeTypes := []string{"test/plain","image/jpeg"}
validation.Field(&form.File, validation.By(validators.UploadedFileMimeType(validMimeTypes)))

func UploadedFileSize

func UploadedFileSize(maxBytes int) validation.RuleFunc

UploadedFileSize checks whether the validated `rest.UploadedFile` size is no more than the provided maxBytes.

Example:

validation.Field(&form.File, validation.By(validators.UploadedFileSize(1000)))

Types

type RecordDataValidator

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

RecordDataValidator defines a model.Record data validator using the provided record constraints and schema.

func NewRecordDataValidator

func NewRecordDataValidator(
	dao *daos.Dao,
	record *models.Record,
	uploadedFiles map[string][]*filesystem.File,
) *RecordDataValidator

NewRecordDataValidator creates new models.Record data validator using the provided record constraints and schema.

Example:

validator := NewRecordDataValidator(app.Dao(), record, nil)
err := validator.Validate(map[string]any{"test":123})

func (*RecordDataValidator) Validate

func (validator *RecordDataValidator) Validate(data map[string]any) error

Validate validates the provided `data` by checking it against the validator record constraints and schema.

Jump to

Keyboard shortcuts

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