customfield

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const PostScriptSlug = "post_script"

PostScriptSlug is the reserved custom-field slug rendering verbatim at post end.

Variables

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

func ValidateFieldName(name string) error

ValidateFieldName requires a non-blank name within length limits.

func ValidateFieldSlug

func ValidateFieldSlug(slug string) error

ValidateFieldSlug requires a lowercase snake_case slug within limits.

func ValidateFieldType

func ValidateFieldType(t FieldType) error

ValidateFieldType rejects unknown field types.

func ValidateFields

func ValidateFields(fields []FieldSchema) error

ValidateFields checks every schema and rejects duplicate slugs.

func ValidateMaxLength

func ValidateMaxLength(t FieldType, maxLength *int) error

ValidateMaxLength allows max_length only on text and textarea fields.

func ValidateNumberRange

func ValidateNumberRange(t FieldType, min, max *float64) error

ValidateNumberRange rejects min > max on number fields; other types and absent bounds pass.

func ValidateSelectOptions

func ValidateSelectOptions(t FieldType, options []string) error

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"
)

Jump to

Keyboard shortcuts

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