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 ¶
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})