validate

package
v0.0.0-...-d761283 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: MIT Imports: 6 Imported by: 0

README

Validate functions

All the functions in this directory are used to validate data, all of them MUST BE PURE FUNCTIONS.

https://en.wikipedia.org/wiki/Pure_function

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CronExpression

func CronExpression(expression string) bool

CronExpression validates a cron expression.

It only supports 5 fields (minute, hour, day of month, month, day of week).

It returns a boolean indicating whether the expression is valid or not.

func Email

func Email(email string) bool

Email validates an email address. It returns a boolean indicating whether the email is valid or not.

func JSON

func JSON(jsonStr string) bool

JSON validates a JSON string, it returns a boolean indicating whether the JSON is valid or not.

Types

type StructError

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

StructError is the error returned by Struct.

func Struct

func Struct[T any](sPointer *T) *StructError

Struct validates the given struct using go-playground/validator.

func StructSlice

func StructSlice[T any](sPointerSlice *[]T) *StructError

StructSlice validates the given slice of structs using go-playground/validator.

func (*StructError) AddErr

func (e *StructError) AddErr(err error)

AddErr adds an error.

func (*StructError) Error

func (e *StructError) Error() string

Error returns all the errors as a string separated by commas.

func (*StructError) Errors

func (e *StructError) Errors() []string

Errors returns all the errors as a slice of strings.

func (*StructError) ErrorsRaw

func (e *StructError) ErrorsRaw() []error

ErrorsRaw returns all the errors as a slice of errors.

func (*StructError) HasErrs

func (e *StructError) HasErrs() bool

HasErrs returns true if there are errors.

func (*StructError) SetErrs

func (e *StructError) SetErrs(errs []error)

SetErrs sets the errors.

Jump to

Keyboard shortcuts

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