fieldtype

package
v0.1.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllFieldtype

func GetAllFieldtype() map[string]Definition

GetAllFieldtype get all fieldtype

func IsEmptyInput

func IsEmptyInput(input interface{}) bool

IsEmptyInput returns if it's an empty input. The input can be not string(eg. int - definately not empty)

func Register

func Register(definition Definition)

Register registers a fieldtype

Types

type Definition

type Definition struct {
	Name       string                 //eg. text
	DataType   string                 //eg. string or eg "fieldtype.CustomString"
	Package    string                 //empty if there is no additional package, otherwise it's like 'mycompany.fieldtype'. Used for generating entity's import.
	NewHandler func(FieldDef) Handler //callback to create new handler for this fieldtype
}

Definition includes a fieldtype basic information

func GetFieldtype

func GetFieldtype(fieldtype string) Definition

GetFieldtype return a fieldtype

type EmptyError

type EmptyError struct {
}

Empty Error

func (EmptyError) Error

func (err EmptyError) Error() string

type Event

type Event interface {
	BeforeStore(ctx context.Context, value interface{}, existing interface{}, mode string) (interface{}, error)

	AfterDelete(ctx context.Context, value interface{}) error
}

BeforeSaving is implemented when fieldtype has event before saving and transaction starts.

type FieldDef

type FieldDef struct {
	Identifier   string          `json:"identifier"`
	Name         string          `json:"name"`
	FieldType    string          `json:"type"`
	DefaultValue interface{}     `json:"default_value"` //eg. checkbox 1 means checked
	Required     bool            `json:"required"`
	Description  string          `json:"description"`
	IsOutput     bool            `json:"is_output"`
	Parameters   FieldParameters `json:"parameters"`
	Children     []FieldDef      `json:"children"`
}

Content field definition

func (*FieldDef) GetSubFields

func (cf *FieldDef) GetSubFields(callback ...func(*FieldDef)) map[string]FieldDef

type FieldParameters

type FieldParameters map[string]interface{}

type Handler

type Handler interface {
	//Load from input, should return the value of BaseType, (eg. int), return error or validation error or empty error
	LoadInput(ctx context.Context, input interface{}, mode string) (interface{}, error)

	//output database field. todo: can support this to generate database field automatically
	DBField() string
}

Fieldtyper is a implementation of a fieldtype, including main logic

func GethHandler

func GethHandler(def FieldDef) Handler

type RelationParameters

type RelationParameters struct {
	Type      string                 `json:"type"`
	Value     string                 `json:"value"`
	Condition map[string]interface{} `json:"condition"`
}

func ConvertRelationParams

func ConvertRelationParams(params FieldParameters) (RelationParameters, error)

Convert to parameters obj

type StoreHandler

type StoreHandler interface {
	Store(ctx context.Context, value interface{}, contentType string, cid int, transaction *sql.Tx) error
}

type ValidateDefinition

type ValidateDefinition interface {
	ValidateDefinition() error
}

type ValidationError

type ValidationError struct {
	Message string
}

func NewValidationError

func NewValidationError(message string) ValidationError

func (ValidationError) Error

func (err ValidationError) Error() string

Validation error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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