Help us shape the future of Go! Take the 2026 Go Developer Survey

formconfig

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package formconfig defines dynamic form configuration types for authsome.

It supports per-app signup form schemas with custom fields, validation rules, and field rendering hints. Custom field values are stored in User.Metadata.

Index

Constants

View Source
const FormTypeSignup = "signup"

FormTypeSignup is the form type for signup forms.

Variables

This section is empty.

Functions

func ValidateSubmission

func ValidateSubmission(fields []FormField, data map[string]string) map[string]string

ValidateSubmission validates a map of submitted field values against the form field definitions. Returns a map of field key to error message for any invalid fields. An empty map means all fields are valid.

Types

type BrandingConfig

type BrandingConfig struct {
	ID              id.BrandingConfigID `json:"id"`
	OrgID           id.OrgID            `json:"org_id"`
	AppID           id.AppID            `json:"app_id"`
	LogoURL         string              `json:"logo_url,omitempty"`
	PrimaryColor    string              `json:"primary_color,omitempty"`
	BackgroundColor string              `json:"background_color,omitempty"`
	AccentColor     string              `json:"accent_color,omitempty"`
	FontFamily      string              `json:"font_family,omitempty"`
	CustomCSS       string              `json:"custom_css,omitempty"`
	CompanyName     string              `json:"company_name,omitempty"`
	Tagline         string              `json:"tagline,omitempty"`
	CreatedAt       time.Time           `json:"created_at"`
	UpdatedAt       time.Time           `json:"updated_at"`
}

BrandingConfig defines per-organization styling overrides for auth pages.

type BrandingStore

type BrandingStore interface {
	GetBranding(ctx context.Context, orgID id.OrgID) (*BrandingConfig, error)
	SaveBranding(ctx context.Context, b *BrandingConfig) error
	DeleteBranding(ctx context.Context, orgID id.OrgID) error
}

BrandingStore defines persistence operations for branding configurations.

type FieldType

type FieldType string

FieldType represents the type of a form field.

const (
	FieldText        FieldType = "text"
	FieldEmail       FieldType = "email"
	FieldNumber      FieldType = "number"
	FieldTel         FieldType = "tel"
	FieldURL         FieldType = "url"
	FieldDate        FieldType = "date"
	FieldTextarea    FieldType = "textarea"
	FieldSelect      FieldType = "select"
	FieldCheckbox    FieldType = "checkbox"
	FieldRadio       FieldType = "radio"
	FieldSwitch      FieldType = "switch"
	FieldObjectArray FieldType = "object_array"
)

Supported field types.

type FormConfig

type FormConfig struct {
	ID        id.FormConfigID `json:"id"`
	AppID     id.AppID        `json:"app_id"`
	FormType  string          `json:"form_type"` // "signup", future: "profile_edit"
	Fields    []FormField     `json:"fields"`
	Active    bool            `json:"active"`
	Version   int             `json:"version"`
	CreatedAt time.Time       `json:"created_at"`
	UpdatedAt time.Time       `json:"updated_at"`
}

FormConfig defines a dynamic form schema for a specific app and form type.

type FormField

type FormField struct {
	Key         string         `json:"key"` // stored as key in User.Metadata
	Label       string         `json:"label"`
	Type        FieldType      `json:"type"`
	Placeholder string         `json:"placeholder,omitempty"`
	Description string         `json:"description,omitempty"`
	Options     []SelectOption `json:"options,omitempty"` // for select/radio/checkbox
	Default     string         `json:"default,omitempty"`
	Validation  Validation     `json:"validation,omitempty"`
	Order       int            `json:"order"`
}

FormField defines a single custom field in a form configuration.

type SelectOption

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

SelectOption represents a single option for select, radio, or checkbox fields.

type Store

type Store interface {
	CreateFormConfig(ctx context.Context, fc *FormConfig) error
	GetFormConfig(ctx context.Context, appID id.AppID, formType string) (*FormConfig, error)
	UpdateFormConfig(ctx context.Context, fc *FormConfig) error
	DeleteFormConfig(ctx context.Context, appID id.AppID, formType string) error
	ListFormConfigs(ctx context.Context, appID id.AppID) ([]*FormConfig, error)
}

Store defines persistence operations for form configurations.

type Validation

type Validation struct {
	Required bool   `json:"required,omitempty"`
	MinLen   int    `json:"min_len,omitempty"`
	MaxLen   int    `json:"max_len,omitempty"`
	Pattern  string `json:"pattern,omitempty"` // regex pattern
	Min      *int   `json:"min,omitempty"`     // for number fields
	Max      *int   `json:"max,omitempty"`     // for number fields
}

Validation defines server-side and client-side validation rules for a form field.

Jump to

Keyboard shortcuts

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