types

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

This section is empty.

Types

type Config

type Config struct {
	Title  string
	Fields FormFields
}

func (Config) GetFields

func (c Config) GetFields() FormFields

func (Config) GetTitle

func (c Config) GetTitle() string

type CustomField

type CustomField struct {
	Lbl  string
	DVal string
	Grp  string
}

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 CustomizableField interface {
	FormInput[FormInputObject[any]]
	Label() string
	DefaultValue() string
	Group() string
}

type DataExporter

type DataExporter interface {
	ExportToCSV(filename string) error
	ExportToYAML(filename string) error
	ExportToJSON(filename string) error
	ExportToXML(filename string) error
	ExportToExcel(filename string) error
	ExportToPDF(filename string) error
	ExportToMarkdown(filename string) error
}

type FieldAlignment added in v1.1.2

type FieldAlignment string
const (
	AlignmentDefault FieldAlignment = "default"
	AlignmentLeft    FieldAlignment = "left"
	AlignmentCenter  FieldAlignment = "center"
	AlignmentRight   FieldAlignment = "right"
)

func (FieldAlignment) Description added in v1.1.2

func (f FieldAlignment) Description() string

func (FieldAlignment) String added in v1.1.2

func (f FieldAlignment) String() string

type FieldDefinition added in v1.1.2

type FieldDefinition interface {
	Description() string
	String() string
}

type FieldPosition added in v1.1.2

type FieldPosition string
const (
	PositionDefault FieldPosition = "default"
	PositionTop     FieldPosition = "top"
	PositionBottom  FieldPosition = "bottom"
)

func (FieldPosition) Description added in v1.1.2

func (f FieldPosition) Description() string

func (FieldPosition) String added in v1.1.2

func (f FieldPosition) String() string

type FieldRule added in v1.1.2

type FieldRule interface {
	Validate(value string) error
}

type FieldSize added in v1.1.2

type FieldSize string
const (
	SizeDefault FieldSize = "default"
	SizeSmall   FieldSize = "small"
	SizeLarge   FieldSize = "large"
)

func (FieldSize) Description added in v1.1.2

func (f FieldSize) Description() string

func (FieldSize) String added in v1.1.2

func (f FieldSize) String() string

type FieldType added in v1.1.2

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 added in v1.1.2

func (f FieldType) Description() string

func (FieldType) String added in v1.1.2

func (f FieldType) String() string

type FormConfig

type FormConfig struct {
	Title string
	FormFields
}

func NewFormConfig added in v1.2.0

func NewFormConfig(title string, fields []FormInputObject[any]) FormConfig

func (FormConfig) AddField added in v1.2.0

func (f FormConfig) AddField(field FormInputObject[any])

func (FormConfig) GetField added in v1.2.0

func (f FormConfig) GetField(name string) FormInputObject[any]

func (FormConfig) GetFieldValue added in v1.2.0

func (f FormConfig) GetFieldValue(name string) any

func (FormConfig) GetFields added in v1.1.2

func (f FormConfig) GetFields() []FormInputObject[any]

func (FormConfig) GetTitle added in v1.1.2

func (f FormConfig) GetTitle() string

func (FormConfig) RemoveField added in v1.2.0

func (f FormConfig) RemoveField(name string) error

func (FormConfig) SetField added in v1.2.0

func (f FormConfig) SetField(name string, field FormInputObject[any]) error

func (FormConfig) SetFieldValue added in v1.2.0

func (f FormConfig) SetFieldValue(name string, value any) error

func (FormConfig) SetTitle added in v1.2.0

func (f FormConfig) SetTitle(title string)

type FormError added in v1.1.2

type FormError interface {
	Error() string
	ErrorOrNil() error
	FieldError() map[string]string
	FieldsError() map[string]string
}

Form and Field Error interface and types

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 added in v1.1.2

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 added in v1.1.2

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 added in v1.1.2

func NewFormInput[T FormInputObject[any]](t T) FormInput[T]

func NewFormInputFromBytes added in v1.1.2

func NewFormInputFromBytes[T FormInputObject[any]](b []byte) FormInput[T]

func NewFormInputFromMap added in v1.1.2

func NewFormInputFromMap[T FormInputObject[any]](m map[string]interface{}) FormInput[T]

func NewFormInputFromString added in v1.1.2

func NewFormInputFromString[T FormInputObject[any]](str string) FormInput[T]

type FormInputObject added in v1.1.2

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 added in v1.2.0

func NewFormInputList[T any](t []T) []FormInputObject[T]

func NewFormInputListFromBytes added in v1.2.0

func NewFormInputListFromBytes[T any](b [][]byte) []FormInputObject[T]

func NewFormInputListFromInterface added in v1.2.0

func NewFormInputListFromInterface[T any](i []interface{}) []FormInputObject[T]

func NewFormInputListFromMap added in v1.2.0

func NewFormInputListFromMap[T any](m []map[string]interface{}) []FormInputObject[T]

func NewFormInputListFromString added in v1.2.0

func NewFormInputListFromString[T any](str []string) []FormInputObject[T]

func NewFormInputObject added in v1.1.2

func NewFormInputObject[T any](t T) FormInputObject[T]

func NewFormInputObjectFromBytes added in v1.1.2

func NewFormInputObjectFromBytes[T any](b []byte) FormInputObject[T]

func NewFormInputObjectFromMap added in v1.1.2

func NewFormInputObjectFromMap[T any](m map[string]interface{}) FormInputObject[T]

func NewFormInputObjectFromString added in v1.1.2

func NewFormInputObjectFromString[T any](str string) FormInputObject[T]

type FormInputValidationCustom added in v1.1.2

type FormInputValidationCustom func(value string) error

type FormInputValidationObject added in v1.1.2

type FormInputValidationObject[T any] func(value T) error

type FormInputValidationRule added in v1.1.2

type FormInputValidationRule[T any] struct {
	Min, Max  int
	ObjFunc   FormInputValidationObject[T]
	Challenge FormInputValidationCustom
	StrFunc   FormInputValidationString
}

type FormInputValidationString added in v1.1.2

type FormInputValidationString func(value string) error

type FormPart added in v1.1.2

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 added in v1.1.2

func (s FormPart) GetLeftBound() int

func (FormPart) GetLowerBound added in v1.1.2

func (s FormPart) GetLowerBound() int

func (FormPart) GetRightBound added in v1.1.2

func (s FormPart) GetRightBound() int

func (FormPart) GetUpperBound added in v1.1.2

func (s FormPart) GetUpperBound() int

func (FormPart) GetWidth added in v1.1.2

func (s FormPart) GetWidth() int

type Input added in v1.1.2

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 added in v1.1.2

func NewInput[T FormInputObject[any]](t T) *Input[T]

func (*Input[T]) Description added in v1.2.0

func (s *Input[T]) Description() string

func (*Input[T]) Error added in v1.1.2

func (s *Input[T]) Error() string

func (*Input[T]) FromMap added in v1.1.2

func (s *Input[T]) FromMap(m map[string]interface{}) error

func (*Input[T]) FromString added in v1.1.2

func (s *Input[T]) FromString(str string) error

func (*Input[T]) GetError added in v1.1.2

func (s *Input[T]) GetError() string

func (*Input[T]) GetName added in v1.2.0

func (s *Input[T]) GetName() string

func (*Input[T]) GetType added in v1.1.2

func (s *Input[T]) GetType() reflect.Type

func (*Input[T]) GetValue added in v1.1.2

func (s *Input[T]) GetValue() T

func (*Input[T]) IsRequired added in v1.1.2

func (s *Input[T]) IsRequired() bool

func (*Input[T]) MaxValue added in v1.1.2

func (s *Input[T]) MaxValue() int

func (*Input[T]) MinValue added in v1.1.2

func (s *Input[T]) MinValue() int

func (*Input[T]) Placeholder added in v1.1.2

func (s *Input[T]) Placeholder() string

func (*Input[T]) SetMaxValue added in v1.1.2

func (s *Input[T]) SetMaxValue(i int)

func (*Input[T]) SetMinValue added in v1.1.2

func (s *Input[T]) SetMinValue(min int)

func (*Input[T]) SetPlaceholder added in v1.1.2

func (s *Input[T]) SetPlaceholder(ph string)

func (*Input[T]) SetRequired added in v1.1.2

func (s *Input[T]) SetRequired(req bool)

func (*Input[T]) SetValidation added in v1.1.2

func (s *Input[T]) SetValidation(validation func(string, func(interface{}) error) error)

func (*Input[T]) SetValidationRules added in v1.1.2

func (s *Input[T]) SetValidationRules(rules []ValidationRule)

func (*Input[T]) SetValue added in v1.1.2

func (s *Input[T]) SetValue(val T) error

func (*Input[T]) String added in v1.1.2

func (s *Input[T]) String() string

func (*Input[T]) ToMap added in v1.1.2

func (s *Input[T]) ToMap() map[string]interface{}

func (*Input[T]) Validate added in v1.1.2

func (s *Input[T]) Validate() error

func (*Input[T]) Validation added in v1.1.2

func (s *Input[T]) Validation() func(string, func(interface{}) error) error

func (*Input[T]) ValidationRules added in v1.1.2

func (s *Input[T]) ValidationRules() []ValidationRule

type InputObject added in v1.1.2

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 added in v1.1.2

func NewInputObject[T any](t T) *InputObject[T]

func (*InputObject[T]) GetName added in v1.2.0

func (s *InputObject[T]) GetName() string

func (*InputObject[T]) GetType added in v1.1.2

func (s *InputObject[T]) GetType() reflect.Type

func (*InputObject[T]) GetValue added in v1.1.2

func (s *InputObject[T]) GetValue() T

func (*InputObject[T]) SetValue added in v1.1.2

func (s *InputObject[T]) SetValue(val T) error

type Loader added in v1.1.2

type Loader interface {
	AddMessage(LoaderMessage)
	AddMessages([]LoaderMessage)
	ClearMessages()
	GetMessages() []LoaderMessage
	GetMessagesCount() int
	GetLastMessage() LoaderMessage
	GetFirstMessage() LoaderMessage
}

type LoaderMessage added in v1.1.2

type LoaderMessage struct {
	Message    string
	DelayAfter int
	Icon       string
	Color      string

	Progress        bool
	ProgressProcess interface{}
	ProgressTotal   interface{}
	ProgressCurrent interface{}
	ProgressMessage string
	ProgressIcon    string
}

type LoaderOrchestrator added in v1.1.2

type LoaderOrchestrator struct {
	LoaderMessages []LoaderMessage
}

func NewLoaderOrchestrator added in v1.1.2

func NewLoaderOrchestrator() *LoaderOrchestrator

func (*LoaderOrchestrator) AddMessage added in v1.1.2

func (l *LoaderOrchestrator) AddMessage(m LoaderMessage)

func (*LoaderOrchestrator) AddMessages added in v1.1.2

func (l *LoaderOrchestrator) AddMessages(m []LoaderMessage)

func (*LoaderOrchestrator) ClearMessages added in v1.1.2

func (l *LoaderOrchestrator) ClearMessages()

func (*LoaderOrchestrator) GetFirstMessage added in v1.1.2

func (l *LoaderOrchestrator) GetFirstMessage() LoaderMessage

func (*LoaderOrchestrator) GetLastMessage added in v1.1.2

func (l *LoaderOrchestrator) GetLastMessage() LoaderMessage

func (*LoaderOrchestrator) GetMessages added in v1.1.2

func (l *LoaderOrchestrator) GetMessages() []LoaderMessage

func (*LoaderOrchestrator) GetMessagesCount added in v1.1.2

func (l *LoaderOrchestrator) GetMessagesCount() int

type MultiTableHandler added in v1.2.0

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

func (*MultiTableHandler) GetHeaders added in v1.2.0

func (h *MultiTableHandler) GetHeaders() []string

func (*MultiTableHandler) GetRows added in v1.2.0

func (h *MultiTableHandler) GetRows() [][]string

func (*MultiTableHandler) NextTable added in v1.2.0

func (h *MultiTableHandler) NextTable()

func (*MultiTableHandler) PreviousTable added in v1.2.0

func (h *MultiTableHandler) PreviousTable()

type MultiTableManager added in v1.2.0

type MultiTableManager struct {
	Handlers []TableDataHandler
	Current  int
}

func (*MultiTableManager) GetCurrentHandler added in v1.2.0

func (m *MultiTableManager) GetCurrentHandler() TableDataHandler

func (*MultiTableManager) Next added in v1.2.0

func (m *MultiTableManager) Next()

func (*MultiTableManager) Previous added in v1.2.0

func (m *MultiTableManager) Previous()

type Shortcut added in v1.1.2

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 added in v1.1.2

func (s Shortcut) Description() string

func (Shortcut) String added in v1.1.2

func (s Shortcut) String() string

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
}

type TableHandler added in v1.1.2

type TableHandler struct {
	TableDataHandler
	Headers []string
	Rows    [][]string
}

func (*TableHandler) GetArrayMap added in v1.1.2

func (h *TableHandler) GetArrayMap() map[string][]string

func (*TableHandler) GetByteMap added in v1.1.2

func (h *TableHandler) GetByteMap() map[string][]byte

func (*TableHandler) GetHashMap added in v1.1.2

func (h *TableHandler) GetHashMap() map[string]string

func (*TableHandler) GetHeaders added in v1.1.2

func (h *TableHandler) GetHeaders() []string

func (*TableHandler) GetObjectMap added in v1.1.2

func (h *TableHandler) GetObjectMap() []map[string]string

func (*TableHandler) GetRows added in v1.1.2

func (h *TableHandler) GetRows() [][]string

type TableHandlerWithContext added in v1.2.0

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 added in v1.1.2

func (v ValidationRule) Description() string

func (ValidationRule) String added in v1.1.2

func (v ValidationRule) String() string

func (ValidationRule) Validate

func (v ValidationRule) Validate(value string, customCheck func(interface{}) error) error

Jump to

Keyboard shortcuts

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