Documentation
¶
Overview ¶
Package types provides type definitions and interfaces for form handling and validation.
Index ¶
- Variables
- func IsEqual(a, b string) bool
- func SanitizeQuotesAndSpaces(input string) string
- type Config
- type CustomField
- type CustomizableField
- type DataExporter
- type FieldAlignment
- type FieldDefinition
- type FieldPosition
- type FieldRule
- type FieldSize
- type FieldType
- type FormConfig
- func (f *FormConfig) AddField(field FormInputObject[any])
- func (f *FormConfig) GetField(name string) FormInputObject[any]
- func (f *FormConfig) GetFieldValue(name string) any
- func (f *FormConfig) GetFields() []FormInputObject[any]
- func (f *FormConfig) GetTitle() string
- func (f *FormConfig) RemoveField(name string) error
- func (f *FormConfig) SetField(name string, field FormInputObject[any]) error
- func (f *FormConfig) SetFieldValue(name string, value any) error
- func (f *FormConfig) SetTitle(title string)
- type FormError
- type FormFields
- type FormGroup
- type FormInput
- type FormInputObject
- func NewFormInputList[T any](t []T) []FormInputObject[T]
- func NewFormInputListFromBytes[T any](b [][]byte) []FormInputObject[T]
- func NewFormInputListFromInterface[T any](i []interface{}) []FormInputObject[T]
- func NewFormInputListFromMap[T any](m []map[string]interface{}) []FormInputObject[T]
- func NewFormInputListFromString[T any](str []string) []FormInputObject[T]
- func NewFormInputObject[T any](t T) FormInputObject[T]
- func NewFormInputObjectFromBytes[T any](b []byte) FormInputObject[T]
- func NewFormInputObjectFromMap[T any](m map[string]interface{}) FormInputObject[T]
- func NewFormInputObjectFromString[T any](str string) FormInputObject[T]
- type FormInputValidationCustom
- type FormInputValidationObject
- type FormInputValidationRule
- type FormInputValidationString
- type FormPart
- type IMapper
- type Input
- func (s *Input[T]) Description() string
- func (s *Input[T]) Error() string
- func (s *Input[T]) FromMap(m map[string]interface{}) error
- func (s *Input[T]) FromString(str string) error
- func (s *Input[T]) GetError() string
- func (s *Input[T]) GetName() string
- func (s *Input[T]) GetType() reflect.Type
- func (s *Input[T]) GetValue() T
- func (s *Input[T]) IsRequired() bool
- func (s *Input[T]) MaxValue() int
- func (s *Input[T]) MinValue() int
- func (s *Input[T]) Placeholder() string
- func (s *Input[T]) SetMaxValue(i int)
- func (s *Input[T]) SetMinValue(min int)
- func (s *Input[T]) SetPlaceholder(ph string)
- func (s *Input[T]) SetRequired(req bool)
- func (s *Input[T]) SetValidation(validation func(string, func(interface{}) error) error)
- func (s *Input[T]) SetValidationRules(rules []ValidationRule)
- func (s *Input[T]) SetValue(val T) error
- func (s *Input[T]) String() string
- func (s *Input[T]) ToMap() map[string]interface{}
- func (s *Input[T]) Validate() error
- func (s *Input[T]) Validation() func(string, func(interface{}) error) error
- func (s *Input[T]) ValidationRules() []ValidationRule
- type InputObject
- type Loader
- type LoaderMessage
- type LoaderOrchestrator
- func (l *LoaderOrchestrator) AddMessage(m LoaderMessage)
- func (l *LoaderOrchestrator) AddMessages(m []LoaderMessage)
- func (l *LoaderOrchestrator) ClearMessages()
- func (l *LoaderOrchestrator) GetFirstMessage() LoaderMessage
- func (l *LoaderOrchestrator) GetLastMessage() LoaderMessage
- func (l *LoaderOrchestrator) GetMessages() []LoaderMessage
- func (l *LoaderOrchestrator) GetMessagesCount() int
- type Mapper
- type MultiTableHandler
- type MultiTableManager
- type Shortcut
- type TableDataHandler
- type TableHandler
- func (h *TableHandler) GetArrayMap() map[string][]string
- func (h *TableHandler) GetByteMap() map[string][]byte
- func (h *TableHandler) GetHashMap() map[string]string
- func (h *TableHandler) GetHeaders() []string
- func (h *TableHandler) GetObjectMap() []map[string]string
- func (h *TableHandler) GetRows() [][]string
- type TableHandlerWithContext
- type ValidationRule
Constants ¶
This section is empty.
Variables ¶
var ( ErrRequired = &formError{Rule: "Required", Message: "This field is required"} ErrInvalidEmail = &formError{Rule: "InvalidEmail", Message: "This field must be a valid email address"} ErrInvalidURL = &formError{Rule: "InvalidURL", Message: "This field must be a valid URL"} ErrInvalidIP = &formError{Rule: "InvalidIP", Message: "This field must be a valid IP address"} ErrInvalidPort = &formError{Rule: "InvalidPort", Message: "This field must be a valid Port number"} ErrInvalidMin = &formError{Rule: "InvalidMin", Message: "This field must be a minimum of %d"} ErrInvalidMax = &formError{Rule: "InvalidMax", Message: "This field must be a maximum of %d"} ErrInvalidMinLen = &formError{Rule: "InvalidMinLen", Message: "This field must be a minimum length of %d"} ErrInvalidMaxLen = &formError{Rule: "InvalidMaxLen", Message: "This field must be a maximum length of %d"} ErrInvalidRegexp = &formError{Rule: "InvalidRegexp", Message: "This field must match the regular expression %s"} ErrInvalidPattern = &formError{Rule: "InvalidPattern", Message: "This field must match the pattern %s"} ErrInvalidCustom = &formError{Rule: "InvalidCustom", Message: "This field must match the custom rule"} ErrInvalidCustomCheck = &formError{Rule: "InvalidCustomCheck", Message: "This field must match the custom check"} )
Functions ¶
func SanitizeQuotesAndSpaces ¶
Types ¶
type Config ¶
type Config struct {
Title string
Fields FormFields
}
func (Config) GetFields ¶
func (c Config) GetFields() FormFields
type CustomField ¶
func (CustomField) DefaultValue ¶
func (f CustomField) DefaultValue() string
func (CustomField) Group ¶
func (f CustomField) Group() string
func (CustomField) Label ¶
func (f CustomField) Label() string
type CustomizableField ¶
type DataExporter ¶
type FieldAlignment ¶
type FieldAlignment string
const ( AlignmentDefault FieldAlignment = "default" AlignmentLeft FieldAlignment = "left" AlignmentCenter FieldAlignment = "center" AlignmentRight FieldAlignment = "right" )
func (FieldAlignment) Description ¶
func (f FieldAlignment) Description() string
func (FieldAlignment) String ¶
func (f FieldAlignment) String() string
type FieldDefinition ¶
type FieldPosition ¶
type FieldPosition string
const ( PositionDefault FieldPosition = "default" PositionTop FieldPosition = "top" PositionBottom FieldPosition = "bottom" )
func (FieldPosition) Description ¶
func (f FieldPosition) Description() string
func (FieldPosition) String ¶
func (f FieldPosition) String() string
type FieldType ¶
type FieldType string
const ( FieldBool FieldType = "bool" FieldInt FieldType = "int" FieldText FieldType = "text" FieldPass FieldType = "password" FieldDate FieldType = "date" FieldTime FieldType = "time" FieldList FieldType = "list" FieldFile FieldType = "file" FieldTable FieldType = "table" FieldFunction FieldType = "function" )
func (FieldType) Description ¶
type FormConfig ¶
type FormConfig struct {
Title string
FormFields
}
func NewFormConfig ¶
func NewFormConfig(title string, fields []FormInputObject[any]) FormConfig
func (*FormConfig) AddField ¶
func (f *FormConfig) AddField(field FormInputObject[any])
func (*FormConfig) GetField ¶
func (f *FormConfig) GetField(name string) FormInputObject[any]
func (*FormConfig) GetFieldValue ¶
func (f *FormConfig) GetFieldValue(name string) any
func (*FormConfig) GetFields ¶
func (f *FormConfig) GetFields() []FormInputObject[any]
func (*FormConfig) GetTitle ¶
func (f *FormConfig) GetTitle() string
func (*FormConfig) RemoveField ¶
func (f *FormConfig) RemoveField(name string) error
func (*FormConfig) SetField ¶
func (f *FormConfig) SetField(name string, field FormInputObject[any]) error
func (*FormConfig) SetFieldValue ¶
func (f *FormConfig) SetFieldValue(name string, value any) error
func (*FormConfig) SetTitle ¶
func (f *FormConfig) SetTitle(title string)
type FormFields ¶
type FormFields struct {
Title string
Fields []FormInputObject[any]
}
func (FormFields) InputType ¶
func (f FormFields) InputType() string
func (FormFields) Inputs ¶
func (f FormFields) Inputs() []FormInputObject[any]
type FormGroup ¶
type FormGroup interface {
GetFields() FormFields
GetFieldByID(id string) FieldDefinition
GetFieldByIndex(index int) FieldDefinition
GetFieldIndex(id string) int
GetFieldID(index int) string
FieldsCount() int
Validate() error
SetField(index int, field FieldDefinition)
SetFieldByID(id string, field FieldDefinition)
SetFields(fields FormFields)
}
FormGroup is an interface that manages goups of fields. It was created to provide a easy way to manage fields in a form, wrapping them in groups and providing methods to manipulate them.
type FormInput ¶
type FormInput[T any] interface { FieldDefinition FormInputObject[T] Placeholder() string MinValue() int MaxValue() int Validation() func(string, func(interface{}) error) error IsRequired() bool Error() string SetPlaceholder(string) SetRequired(bool) SetMinValue(int) SetMaxValue(int) SetValidation(func(string, func(interface{}) error) error) SetValidationRules([]ValidationRule) ValidationRules() []ValidationRule Validate() error String() string FromString(string) error ToMap() map[string]interface{} FromMap(map[string]interface{}) error }
func NewFormInput ¶
func NewFormInput[T FormInputObject[any]](t T) FormInput[T]
func NewFormInputFromBytes ¶
func NewFormInputFromBytes[T FormInputObject[any]](b []byte) FormInput[T]
func NewFormInputFromMap ¶
func NewFormInputFromMap[T FormInputObject[any]](m map[string]interface{}) FormInput[T]
func NewFormInputFromString ¶
func NewFormInputFromString[T FormInputObject[any]](str string) FormInput[T]
type FormInputObject ¶
type FormInputObject[T any] interface { GetName() string GetType() reflect.Type GetValue() T SetValue(val T) error }
FormInputObject is the most basic form input object. It will be used globally in all form input objects.
func NewFormInputList ¶
func NewFormInputList[T any](t []T) []FormInputObject[T]
func NewFormInputListFromBytes ¶
func NewFormInputListFromBytes[T any](b [][]byte) []FormInputObject[T]
func NewFormInputListFromInterface ¶
func NewFormInputListFromInterface[T any](i []interface{}) []FormInputObject[T]
func NewFormInputListFromMap ¶
func NewFormInputListFromMap[T any](m []map[string]interface{}) []FormInputObject[T]
func NewFormInputListFromString ¶
func NewFormInputListFromString[T any](str []string) []FormInputObject[T]
func NewFormInputObject ¶
func NewFormInputObject[T any](t T) FormInputObject[T]
func NewFormInputObjectFromBytes ¶
func NewFormInputObjectFromBytes[T any](b []byte) FormInputObject[T]
func NewFormInputObjectFromMap ¶
func NewFormInputObjectFromMap[T any](m map[string]interface{}) FormInputObject[T]
func NewFormInputObjectFromString ¶
func NewFormInputObjectFromString[T any](str string) FormInputObject[T]
type FormInputValidationRule ¶
type FormInputValidationRule[T any] struct { Min, Max int ObjFunc FormInputValidationObject[T] Challenge FormInputValidationCustom StrFunc FormInputValidationString }
type FormPart ¶
type FormPart struct {
*lipgloss.Style
FormGroup
Width, Height, MaxWidth, MaxHeight int
Title string
}
FormPart is an interface that agroups fields and provides methods to manipulate them. It is used to group fields, manage screen space and fields distribution on the screen.
func (FormPart) GetLeftBound ¶
func (FormPart) GetLowerBound ¶
func (FormPart) GetRightBound ¶
func (FormPart) GetUpperBound ¶
type IMapper ¶
type IMapper[T any] interface { // SerializeToFile serializes an object of type T to a file in the specified format. SerializeToFile(format string) // DeserializeFromFile deserializes an object of type T from a file in the specified format. DeserializeFromFile(format string) (T, error) // Serialize converts an object of type T to a byte array in the specified format. Serialize(format string) ([]byte, error) // Deserialize converts a byte array in the specified format to an object of type T. Deserialize(data []byte, format string) (T, error) }
IMapper is a generic interface for serializing and deserializing objects of type T.
type Input ¶
type Input[T any] struct { FieldDefinition FormInputObject[T] Name string `json:"name" yaml:"name" gorm:"column:name"` Desc string `json:"description" yaml:"description" gorm:"column:description"` Ph string `json:"placeholder" yaml:"placeholder" gorm:"column:placeholder"` Tp reflect.Type `json:"type" yaml:"type" gorm:"column:type"` Val *T `json:"value" yaml:"value" gorm:"column:value"` Req bool `json:"required" yaml:"required" gorm:"column:required"` Min int `json:"min" yaml:"min" gorm:"column:min"` Max int `json:"max" yaml:"max" gorm:"column:max"` Err string `json:"error" yaml:"error" gorm:"column:error"` ValidationRulesVal []ValidationRule `json:"validation_rules" yaml:"validation_rules" gorm:"column:validation_rules"` }
func NewInput ¶
func NewInput[T FormInputObject[any]](t T) *Input[T]
func (*Input[T]) Description ¶
func (*Input[T]) FromString ¶
func (*Input[T]) IsRequired ¶
func (*Input[T]) Placeholder ¶
func (*Input[T]) SetMaxValue ¶
func (*Input[T]) SetMinValue ¶
func (*Input[T]) SetPlaceholder ¶
func (*Input[T]) SetRequired ¶
func (*Input[T]) SetValidation ¶
func (*Input[T]) SetValidationRules ¶
func (s *Input[T]) SetValidationRules(rules []ValidationRule)
func (*Input[T]) Validation ¶
func (*Input[T]) ValidationRules ¶
func (s *Input[T]) ValidationRules() []ValidationRule
type InputObject ¶
type InputObject[T any] struct { Val T `json:"value" yaml:"value" gorm:"column:value"` Name string `json:"name" yaml:"name" gorm:"column:name"` // contains filtered or unexported fields }
InputObject is a struct that implements the FormInputObject interface. It is used to store the value of the form input object in a serializable. It is used to store the value of the form input object in a serializable and to store metadata for easy and integrated serialization and type conversion.
func NewInputObject ¶
func NewInputObject[T any](t T) *InputObject[T]
func (*InputObject[T]) GetName ¶
func (s *InputObject[T]) GetName() string
func (*InputObject[T]) GetType ¶
func (s *InputObject[T]) GetType() reflect.Type
func (*InputObject[T]) GetValue ¶
func (s *InputObject[T]) GetValue() T
func (*InputObject[T]) SetValue ¶
func (s *InputObject[T]) SetValue(val T) error
type Loader ¶
type Loader interface {
AddMessage(LoaderMessage)
AddMessages([]LoaderMessage)
ClearMessages()
GetMessages() []LoaderMessage
GetMessagesCount() int
GetLastMessage() LoaderMessage
GetFirstMessage() LoaderMessage
}
type LoaderMessage ¶
type LoaderOrchestrator ¶
type LoaderOrchestrator struct {
LoaderMessages []LoaderMessage
}
func NewLoaderOrchestrator ¶
func NewLoaderOrchestrator() *LoaderOrchestrator
func (*LoaderOrchestrator) AddMessage ¶
func (l *LoaderOrchestrator) AddMessage(m LoaderMessage)
func (*LoaderOrchestrator) AddMessages ¶
func (l *LoaderOrchestrator) AddMessages(m []LoaderMessage)
func (*LoaderOrchestrator) ClearMessages ¶
func (l *LoaderOrchestrator) ClearMessages()
func (*LoaderOrchestrator) GetFirstMessage ¶
func (l *LoaderOrchestrator) GetFirstMessage() LoaderMessage
func (*LoaderOrchestrator) GetLastMessage ¶
func (l *LoaderOrchestrator) GetLastMessage() LoaderMessage
func (*LoaderOrchestrator) GetMessages ¶
func (l *LoaderOrchestrator) GetMessages() []LoaderMessage
func (*LoaderOrchestrator) GetMessagesCount ¶
func (l *LoaderOrchestrator) GetMessagesCount() int
type Mapper ¶
type Mapper[T any] struct { // contains filtered or unexported fields }
Mapper is a generic struct that implements the IMapper interface for serializing and deserializing objects.
func NewMapperPtr ¶
NewMapperPtr creates a new instance of Mapper.
func NewMapperType ¶
NewMapperType creates a new instance of Mapper.
func NewMapperTypeWithObject ¶
NewMapperTypeWithObject creates a new instance of Mapper.
func (*Mapper[T]) Deserialize ¶
Deserialize converts a byte array in the specified format to an object of type T.
func (*Mapper[T]) DeserializeFromFile ¶
DeserializeFromFile deserializes an object of type T from a file in the specified format.
func (*Mapper[T]) Serialize ¶
Serialize converts an object of type T to a byte array in the specified format.
func (*Mapper[T]) SerializeToFile ¶
SerializeToFile serializes an object of type T to a file in the specified format.
type MultiTableHandler ¶
type MultiTableHandler struct {
// contains filtered or unexported fields
}
func (*MultiTableHandler) GetHeaders ¶
func (h *MultiTableHandler) GetHeaders() []string
func (*MultiTableHandler) GetRows ¶
func (h *MultiTableHandler) GetRows() [][]string
func (*MultiTableHandler) NextTable ¶
func (h *MultiTableHandler) NextTable()
func (*MultiTableHandler) PreviousTable ¶
func (h *MultiTableHandler) PreviousTable()
type MultiTableManager ¶
type MultiTableManager struct {
Handlers []TableDataHandler
Current int
}
func (*MultiTableManager) GetCurrentHandler ¶
func (m *MultiTableManager) GetCurrentHandler() TableDataHandler
func (*MultiTableManager) Next ¶
func (m *MultiTableManager) Next()
func (*MultiTableManager) Previous ¶
func (m *MultiTableManager) Previous()
type Shortcut ¶
type Shortcut string
const ( Q Shortcut = "q" F Shortcut = "f" UP Shortcut = "up" DOWN Shortcut = "down" LEFT Shortcut = "left" RIGHT Shortcut = "right" DEL Shortcut = "del" TAB Shortcut = "tab" ESC Shortcut = "esc" ENTER Shortcut = "enter" CTRLA Shortcut = "ctrl+a" CTRLE Shortcut = "ctrl+e" CTRLR Shortcut = "ctrl+r" CTRLC Shortcut = "ctrl+c" CTRLH Shortcut = "ctrl+h" SHIFTTAB Shortcut = "shift+tab" )
func (Shortcut) Description ¶
type TableDataHandler ¶
type TableDataHandler interface {
GetHeaders() []string
GetRows() [][]string
GetArrayMap() map[string][]string
GetHashMap() map[string]string
GetObjectMap() []map[string]string
GetByteMap() map[string][]byte
}
func NewTableHandler ¶
func NewTableHandler(headers []string, rows [][]string) TableDataHandler
func NewTableHandlerFromMap ¶
func NewTableHandlerFromMap(data map[string][]string) TableDataHandler
func NewTableHandlerFromRows ¶
func NewTableHandlerFromRows(headers []string, rows [][]string) TableDataHandler
type TableHandler ¶
type TableHandler struct {
TableDataHandler
Headers []string
Rows [][]string
}
func (*TableHandler) GetArrayMap ¶
func (h *TableHandler) GetArrayMap() map[string][]string
func (*TableHandler) GetByteMap ¶
func (h *TableHandler) GetByteMap() map[string][]byte
func (*TableHandler) GetHashMap ¶
func (h *TableHandler) GetHashMap() map[string]string
func (*TableHandler) GetHeaders ¶
func (h *TableHandler) GetHeaders() []string
func (*TableHandler) GetObjectMap ¶
func (h *TableHandler) GetObjectMap() []map[string]string
func (*TableHandler) GetRows ¶
func (h *TableHandler) GetRows() [][]string
type TableHandlerWithContext ¶
type TableHandlerWithContext struct {
TableHandler
Context string
}
type ValidationRule ¶
type ValidationRule string
const ( Required ValidationRule = "required" Email ValidationRule = "email" URL ValidationRule = "url" IP ValidationRule = "ip" Port ValidationRule = "port" Min ValidationRule = "min" Max ValidationRule = "max" MinLen ValidationRule = "min_len" MaxLen ValidationRule = "max_len" Regexp ValidationRule = "regexp" Pattern ValidationRule = "pattern" )
func (ValidationRule) Description ¶
func (v ValidationRule) Description() string
func (ValidationRule) String ¶
func (v ValidationRule) String() string