Documentation
¶
Index ¶
- Constants
- Variables
- func ValidateField(f FieldSchema) error
- func ValidateFieldName(name string) error
- func ValidateFieldSlug(slug string) error
- func ValidateFieldType(t FieldType) error
- func ValidateFields(fields []FieldSchema) error
- func ValidateMaxLength(t FieldType, maxLength *int) error
- func ValidateNumberRange(t FieldType, min, max *float64) error
- func ValidateSelectOptions(t FieldType, options []string) error
- type FieldSchema
- type FieldType
Constants ¶
const PostScriptSlug = "post_script"
PostScriptSlug is the reserved custom-field slug rendering verbatim at post end.
Variables ¶
var ( ErrFieldNameRequired = errors.New("field name is required and must be between 1 and 200 characters") ErrFieldSlugInvalid = errors.New("field slug must be between 1 and 200 characters and contain only lowercase letters, numbers, and underscores") ErrFieldTypeInvalid = errors.New("field type must be one of: text, textarea, number, date, datetime, email, url, select, checkbox") ErrSelectRequiresOpts = errors.New("select fields require an options list") ErrSelectEmptyOption = errors.New("select field options must not contain empty or blank strings") ErrNumberMinGTMax = errors.New("min cannot be greater than max") ErrMaxLengthInvalid = errors.New("max_length must be greater than 0 and is only valid for text and textarea fields") ErrDuplicateFieldSlug = errors.New("duplicate field slug") )
Functions ¶
func ValidateField ¶
func ValidateField(f FieldSchema) error
ValidateField checks one field schema: name, slug, type, options, range, and length constraints.
func ValidateFieldName ¶
ValidateFieldName requires a non-blank name within length limits.
func ValidateFieldSlug ¶
ValidateFieldSlug requires a lowercase snake_case slug within limits.
func ValidateFieldType ¶
ValidateFieldType rejects unknown field types.
func ValidateFields ¶
func ValidateFields(fields []FieldSchema) error
ValidateFields checks every schema and rejects duplicate slugs.
func ValidateMaxLength ¶
ValidateMaxLength allows max_length only on text and textarea fields.
func ValidateNumberRange ¶
ValidateNumberRange rejects min > max on number fields; other types and absent bounds pass.
func ValidateSelectOptions ¶
ValidateSelectOptions requires non-blank options for select fields; other types ignore options.
Types ¶
type FieldSchema ¶
type FieldSchema struct {
Name string `json:"name" toml:"name"`
Slug string `json:"slug" toml:"slug"`
Type FieldType `json:"type" toml:"type"`
Required bool `json:"required,omitempty" toml:"required,omitempty"`
Options []string `json:"options,omitempty" toml:"options,omitempty"`
Min *float64 `json:"min,omitempty" toml:"min,omitempty"`
Max *float64 `json:"max,omitempty" toml:"max,omitempty"`
MaxLength *int `json:"maxLength,omitempty" toml:"max_length,omitempty"`
}
FieldSchema describes one custom field: identity, type, and constraints.
type FieldType ¶
type FieldType string
FieldType names a custom-field value kind.
const ( FieldTypeText FieldType = "text" FieldTypeTextarea FieldType = "textarea" FieldTypeNumber FieldType = "number" FieldTypeDate FieldType = "date" FieldTypeDatetime FieldType = "datetime" FieldTypeEmail FieldType = "email" FieldTypeUrl FieldType = "url" FieldTypeSelect FieldType = "select" FieldTypeCheckbox FieldType = "checkbox" )