goFormValidator

package module
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnprocessableContentErrorCode = 400
	UnprocessableContentErrorMsg  = "Unprocessable content"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolAttribute

type BoolAttribute struct {
	FieldAttribute

	Value bool
}

BoolAttribute represents a bool attribute validator.

func (*BoolAttribute) AddError

func (attribute *BoolAttribute) AddError(message string)

AddError adds an error to the bool attribute.

func (*BoolAttribute) GetCode

func (attribute *BoolAttribute) GetCode() string

GetCode returns the code of the bool attribute.

func (*BoolAttribute) GetErrors

func (attribute *BoolAttribute) GetErrors() []interface{}

GetErrors returns the errors of the bool attribute.

func (*BoolAttribute) IsClean

func (attribute *BoolAttribute) IsClean() bool

func (*BoolAttribute) Time

func (attribute *BoolAttribute) Time() *time.Time

func (*BoolAttribute) ValidateFormat

func (attribute *BoolAttribute) ValidateFormat(formatter string, formatterRemind string)

func (*BoolAttribute) ValidateGt

func (attribute *BoolAttribute) ValidateGt(value interface{}, message *string)

func (*BoolAttribute) ValidateGtEq

func (attribute *BoolAttribute) ValidateGtEq(value interface{}, message *string)

func (*BoolAttribute) ValidateLt

func (attribute *BoolAttribute) ValidateLt(value interface{}, message *string)

func (*BoolAttribute) ValidateLtEq

func (attribute *BoolAttribute) ValidateLtEq(value interface{}, message *string)

func (*BoolAttribute) ValidateMax

func (attribute *BoolAttribute) ValidateMax(max interface{}, message *string)

func (*BoolAttribute) ValidateMin

func (attribute *BoolAttribute) ValidateMin(min interface{}, message *string)

func (*BoolAttribute) ValidateRequired

func (attribute *BoolAttribute) ValidateRequired()

ValidateRequired validates if the bool attribute is required.

type FieldAttribute

type FieldAttribute struct {
	Name   string
	Code   string
	Errors []interface{}
}

type FieldAttributeInterface

type FieldAttributeInterface interface {

	// AddError adds an error message to the attribute.
	AddError(message string)
	// GetCode returns the code of the attribute. Use to format the error message.
	GetCode() string
	// GetErrors returns the errors associated with the attribute.
	GetErrors() []interface{}
	// Time returns the time value of the attribute.
	Time() *time.Time
	// IsClean returns true if the attribute has no errors, false otherwise.
	IsClean() bool

	// Validators
	// ValidateRequired validates if the attribute is required.
	ValidateRequired()

	// ValidateMin validates if the attribute is greater than the min value.
	ValidateMin(min interface{}, message *string)
	// ValidateMax validates if the attribute is less than the max value.
	ValidateMax(max interface{}, message *string)
	// ValidateFormat validates if the attribute matches the format of regex. Using regexp.MustCompile & regexp.MatchString
	ValidateFormat(formatter string, formatterRemind string)
	// ValidateGt validates if the attribute is greater than the value.
	ValidateGt(value interface{}, message *string)
	// ValidateGtEq validates if the attribute is greater than or equal to the value.
	ValidateGtEq(value interface{}, message *string)
	// ValidateLt validates if the attribute is less than the value.
	ValidateLt(value interface{}, message *string)
	// ValidateLtEq validates if the attribute is less than or equal to the value.
	ValidateLtEq(value interface{}, message *string)
}

type FloatAttribute

type FloatAttribute[T constraints.Float] struct {
	FieldAttribute
	Value     T
	AllowZero bool
}

func (*FloatAttribute[T]) AddError

func (attribute *FloatAttribute[T]) AddError(message string)

AddError adds an error message to the attribute.

func (*FloatAttribute[T]) GetCode

func (attribute *FloatAttribute[T]) GetCode() string

GetCode returns the code of the attribute.

func (*FloatAttribute[T]) GetErrors

func (attribute *FloatAttribute[T]) GetErrors() []interface{}

GetErrors returns the errors associated with the attribute.

func (*FloatAttribute[T]) GetFieldI18nCode

func (attribute *FloatAttribute[T]) GetFieldI18nCode() string

GetFieldCode returns the code of the bool attribute.

func (*FloatAttribute[T]) IsClean

func (attribute *FloatAttribute[T]) IsClean() bool

func (*FloatAttribute[T]) Time

func (attribute *FloatAttribute[T]) Time() *time.Time

func (*FloatAttribute[T]) ValidateFormat

func (attribute *FloatAttribute[T]) ValidateFormat(formatter string, formatterRemind string)

func (*FloatAttribute[T]) ValidateGt

func (attribute *FloatAttribute[T]) ValidateGt(value interface{}, message *string)

func (*FloatAttribute[T]) ValidateGtEq

func (attribute *FloatAttribute[T]) ValidateGtEq(value interface{}, message *string)

func (*FloatAttribute[T]) ValidateLt

func (attribute *FloatAttribute[T]) ValidateLt(value interface{}, message *string)

func (*FloatAttribute[T]) ValidateLtEq

func (attribute *FloatAttribute[T]) ValidateLtEq(value interface{}, message *string)

func (*FloatAttribute[T]) ValidateMax

func (attribute *FloatAttribute[T]) ValidateMax(max interface{}, message *string)

func (*FloatAttribute[T]) ValidateMin

func (attribute *FloatAttribute[T]) ValidateMin(min interface{}, message *string)

func (*FloatAttribute[T]) ValidateRequired

func (attribute *FloatAttribute[T]) ValidateRequired()

ValidateRequired validates if the attribute is required.

type Form

type Form struct {
	Attributes []FieldAttributeInterface
	Errors     ResourceModificationError
}

func (*Form) AddAttributes

func (form *Form) AddAttributes(attributes ...FieldAttributeInterface)

func (*Form) AddErrorDirectlyToField

func (form *Form) AddErrorDirectlyToField(field string, errors []interface{})

func (*Form) AddNestedErrors

func (form *Form) AddNestedErrors(fieldKey string, index int, errors ResourceModificationError)

func (*Form) GetAttribute

func (form *Form) GetAttribute(code string) FieldAttributeInterface

func (*Form) IsValid

func (form *Form) IsValid() bool

func (*Form) NestedDirectItemFieldKey

func (form *Form) NestedDirectItemFieldKey(wrapperFieldKey string, index int) string

func (*Form) NestedFieldKey

func (form *Form) NestedFieldKey(wrapperFieldKey string, index int, nestedFieldKey string) string

NestedFieldKey output a key for response such as `projectIssueStatuses.1.issueStatusId` use for nested attributes

type IntAttribute

type IntAttribute[T constraints.Signed] struct {
	FieldAttribute
	Value     T
	AllowZero bool
}

func (*IntAttribute[T]) AddError

func (attribute *IntAttribute[T]) AddError(message string)

AddError adds an error message to the attribute.

func (*IntAttribute[T]) GetCode

func (attribute *IntAttribute[T]) GetCode() string

GetCode returns the code of the attribute.

func (*IntAttribute[T]) GetErrors

func (attribute *IntAttribute[T]) GetErrors() []interface{}

GetErrors returns the errors associated with the attribute.

func (*IntAttribute[T]) GetFieldI18nCode

func (attribute *IntAttribute[T]) GetFieldI18nCode() string

GetFieldCode returns the code of the bool attribute.

func (*IntAttribute[T]) IsClean

func (attribute *IntAttribute[T]) IsClean() bool

func (*IntAttribute[T]) Time

func (attribute *IntAttribute[T]) Time() *time.Time

func (*IntAttribute[T]) ValidateFormat

func (attribute *IntAttribute[T]) ValidateFormat(formatter string, formatterRemind string, message *string)

func (*IntAttribute[T]) ValidateGt

func (attribute *IntAttribute[T]) ValidateGt(value interface{}, message *string)

func (*IntAttribute[T]) ValidateGtEq

func (attribute *IntAttribute[T]) ValidateGtEq(value interface{}, message *string)

func (*IntAttribute[T]) ValidateLt

func (attribute *IntAttribute[T]) ValidateLt(value interface{}, message *string)

func (*IntAttribute[T]) ValidateLtEq

func (attribute *IntAttribute[T]) ValidateLtEq(value interface{}, message *string)

func (*IntAttribute[T]) ValidateMax

func (attribute *IntAttribute[T]) ValidateMax(max interface{}, message *string)

func (*IntAttribute[T]) ValidateMin

func (attribute *IntAttribute[T]) ValidateMin(min interface{}, message *string)

func (*IntAttribute[T]) ValidateRequired

func (attribute *IntAttribute[T]) ValidateRequired(message *string)

ValidateRequired validates if the attribute is required.

type NestedSlices

type NestedSlices interface {
	string
}

type ResourceModificationError

type ResourceModificationError map[string][]interface{}

type ResourceModifyErrors

type ResourceModifyErrors struct {
	Field  string   `json:"field"`
	Errors []string `json:"errors"`
}

ResourceModifyErrors represents errors associated with modifying a resource.

type SliceAttribute

type SliceAttribute[T NestedSlices] struct {
	FieldAttribute
	Value *[]T
}

func (*SliceAttribute[T]) AddError

func (attribute *SliceAttribute[T]) AddError(message string)

AddError adds an error message to the attribute.

func (*SliceAttribute[T]) GetCode

func (attribute *SliceAttribute[T]) GetCode() string

GetCode returns the code of the attribute.

func (*SliceAttribute[T]) GetErrors

func (attribute *SliceAttribute[T]) GetErrors() []interface{}

GetErrors returns the errors associated with the attribute.

func (*SliceAttribute[T]) GetFieldI18nCode

func (attribute *SliceAttribute[T]) GetFieldI18nCode() string

GetFieldCode returns the code of the bool attribute.

func (*SliceAttribute[T]) IsClean

func (attribute *SliceAttribute[T]) IsClean() bool

func (*SliceAttribute[T]) Time

func (attribute *SliceAttribute[T]) Time() *time.Time

func (*SliceAttribute[T]) ValidateFormat

func (attribute *SliceAttribute[T]) ValidateFormat(formatter string, formatterRemind string, message *string)

func (*SliceAttribute[T]) ValidateGt

func (attribute *SliceAttribute[T]) ValidateGt(value interface{}, message *string)

func (*SliceAttribute[T]) ValidateGtEq

func (attribute *SliceAttribute[T]) ValidateGtEq(value interface{}, message *string)

func (*SliceAttribute[T]) ValidateLt

func (attribute *SliceAttribute[T]) ValidateLt(value interface{}, message *string)

func (*SliceAttribute[T]) ValidateLtEq

func (attribute *SliceAttribute[T]) ValidateLtEq(value interface{}, message *string)

func (*SliceAttribute[T]) ValidateMax

func (attribute *SliceAttribute[T]) ValidateMax(min interface{}, message *string)

func (*SliceAttribute[T]) ValidateMin

func (attribute *SliceAttribute[T]) ValidateMin(min interface{}, message *string)

func (*SliceAttribute[T]) ValidateRequired

func (attribute *SliceAttribute[T]) ValidateRequired(message *string)

ValidateRequired validates if the attribute is required.

type StringAttribute

type StringAttribute struct {
	FieldAttribute

	Value string
}

StringAttribute represents a string attribute validator.

func (*StringAttribute) AddError

func (attribute *StringAttribute) AddError(message string)

AddError adds an error to the string attribute.

func (*StringAttribute) GetCode

func (attribute *StringAttribute) GetCode() string

GetCode returns the code of the string attribute.

func (*StringAttribute) GetErrors

func (attribute *StringAttribute) GetErrors() []interface{}

GetErrors returns the errors of the string attribute.

func (*StringAttribute) GetFieldI18nCode

func (attribute *StringAttribute) GetFieldI18nCode() string

GetFieldCode returns the code of the bool attribute.

func (*StringAttribute) IsClean

func (attribute *StringAttribute) IsClean() bool

func (*StringAttribute) Time

func (attribute *StringAttribute) Time() *time.Time

func (*StringAttribute) ValidateFormat

func (attribute *StringAttribute) ValidateFormat(formatter string, formatterRemind string, message *string)

func (*StringAttribute) ValidateGt

func (attribute *StringAttribute) ValidateGt(value interface{}, message *string)

func (*StringAttribute) ValidateGtEq

func (attribute *StringAttribute) ValidateGtEq(value interface{}, message *string)

func (*StringAttribute) ValidateLt

func (attribute *StringAttribute) ValidateLt(value interface{}, message *string)

func (*StringAttribute) ValidateLtEq

func (attribute *StringAttribute) ValidateLtEq(value interface{}, message *string)

func (*StringAttribute) ValidateMax

func (attribute *StringAttribute) ValidateMax(max interface{}, message *string)

func (*StringAttribute) ValidateMin

func (attribute *StringAttribute) ValidateMin(min interface{}, message *string)

func (*StringAttribute) ValidateRequired

func (attribute *StringAttribute) ValidateRequired(message *string)

ValidateRequired validates if the string attribute is required.

type TimeAttribute

type TimeAttribute struct {
	FieldAttribute
	Value     string
	TimeValue *time.Time
}

func (*TimeAttribute) AddError

func (attribute *TimeAttribute) AddError(message string)

AddError adds an error to the string attribute.

func (*TimeAttribute) GetCode

func (attribute *TimeAttribute) GetCode() string

GetCode returns the code of the attribute.

func (*TimeAttribute) GetErrors

func (attribute *TimeAttribute) GetErrors() []interface{}

GetErrors returns the errors of the string attribute.

func (*TimeAttribute) IsClean

func (attribute *TimeAttribute) IsClean() bool

func (*TimeAttribute) Time

func (attribute *TimeAttribute) Time() *time.Time

func (*TimeAttribute) ValidateFormat

func (attribute *TimeAttribute) ValidateFormat(formatter string, formatterRemind string, message *string)

func (*TimeAttribute) ValidateGt

func (attribute *TimeAttribute) ValidateGt(value interface{}, message *string)

func (*TimeAttribute) ValidateGtEq

func (attribute *TimeAttribute) ValidateGtEq(value interface{}, message *string)

func (*TimeAttribute) ValidateLt

func (attribute *TimeAttribute) ValidateLt(value interface{}, message *string)

func (*TimeAttribute) ValidateLtEq

func (attribute *TimeAttribute) ValidateLtEq(value interface{}, message *string)

func (*TimeAttribute) ValidateMax

func (attribute *TimeAttribute) ValidateMax(max interface{}, message *string)

func (*TimeAttribute) ValidateMin

func (attribute *TimeAttribute) ValidateMin(min interface{}, message *string)

func (*TimeAttribute) ValidateRequired

func (attribute *TimeAttribute) ValidateRequired(message *string)

ValidateRequired validates if the string attribute is required.

type UnprocessableContentError

type UnprocessableContentError struct {
	Code    int                       `json:"code"`
	Message string                    `json:"message"`
	Errors  ResourceModificationError `json:"errors"`
}

UnprocessableContentError represents an unprocessable content error.

func NewUnprocessableContentError

func NewUnprocessableContentError(message string, errors ResourceModificationError) *UnprocessableContentError

NewUnprocessableContentError creates a new UnprocessableContentError instance with the provided message and errors. If the message is empty, it uses the default error message.

func (*UnprocessableContentError) AddError

func (e *UnprocessableContentError) AddError(field string, errors []interface{})

AddError adds a new ResourceModifyErrors to the UnprocessableContentError.

func (UnprocessableContentError) Error

Error returns the error message.

func (UnprocessableContentError) Extensions

func (e UnprocessableContentError) Extensions() map[string]interface{}

Extensions returns additional data associated with the error.

Jump to

Keyboard shortcuts

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