formgen

package
v0.0.0-...-da23dcd Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelSection = "Section"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldType

type FieldType string

FieldType represents the kind of input widget to render.

const (
	FieldText     FieldType = "text"
	FieldNumber   FieldType = "number"
	FieldCheckbox FieldType = "checkbox"
	FieldSelect   FieldType = "select"
)

type FormField

type FormField struct {
	Name        string    `json:"name"`  // e.g. "Bool.FromStrings.CustomListForTrue"
	Label       string    `json:"label"` // e.g. "CustomListForTrue"
	Type        FieldType `json:"type"`
	Description string    `json:"description,omitempty"` // tooltip/help text from TOML comments

	Value   string   `json:"value"`             // the value as string
	Options []Option `json:"options,omitempty"` // the value only for selects
}

FormField describes a single input field in the form.

type FormModel

type FormModel struct {
	Sections []*FormSection `json:"sections"`
}

FormModel is the root JSON schema for the form.

func Introspect

func Introspect(cfg any) (*FormModel, error)

Introspect walks the provided cfg (must be a pointer to your Config) and builds a FormModel representing each section, its Disabled flag, fields, and nested subsections.

type FormSection

type FormSection struct {
	Title       string         `json:"title"`
	Fields      []FormField    `json:"fields"`
	Subsections []*FormSection `json:"subsections,omitempty"`
}

FormSection represents a group of fields (and nested subsections).

type Option

type Option struct {
	Value string `json:"value"`
	Label string `json:"label"`
}

Option represents one <option> in a <select> box.

type TOMLComments

type TOMLComments map[string]string

TOMLComments holds a mapping of TOML keys to their comment descriptions.

func ParseTOMLComments

func ParseTOMLComments(content string) (TOMLComments, error)

ParseTOMLComments reads TOML content and extracts comments above each field. It builds a map from field paths (e.g., "Bool.FromStrings.CaseInsensitive") to their descriptions.

func (TOMLComments) GetDescription

func (tc TOMLComments) GetDescription(fieldPath string) string

GetDescription returns the description for a given field path. It tries multiple variations to handle nested structures.

Jump to

Keyboard shortcuts

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