models

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package models turns the declarations of the Go model into the data its templates render.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Templates

func Templates() render.Set

Templates is the models template set. Every part renders through part.tmpl; no block can be overridden yet.

Types

type AdditionalView

type AdditionalView struct {
	Receiver string
	Field    string
	Map      string
	Value    string
	Known    []string
	Runtime  string
	Form     string
}

AdditionalView is what the methods of a struct with additional properties need. Field is the field that holds them and Map its type, Value the type of its values, Known the quoted JSON names of the other fields and Runtime the name the runtime package is imported under. Form, the form type, adds UnmarshalForm.

type CheckView

type CheckView struct {
	Errs       string
	Path       string
	Value      string
	Deref      string
	Guard      string
	IsRequired bool
	NullCheck  string
	Calls      []string
	Items      *LoopView
	Values     *LoopView
}

CheckView checks one value. Every text is a Go expression: Calls return an error that is added to Errs under Path, Deref is Value behind its pointer. Guard is what the calls run under, NullCheck the call that rejects a null Nullable.

type ChoiceView

type ChoiceView struct {
	Func    string
	Members []VariantCheckView
}

ChoiceView is the call that checks how many of Members pass: AnyValid or OneValid.

type ConstView

type ConstView struct {
	Name  string
	Value string
}

ConstView is one enum constant; Value is its literal.

type DeclView

type DeclView struct {
	Doc        string
	Name       string
	IsStruct   bool
	IsUnion    bool
	IsEnum     bool
	IsAlias    bool
	IsDefined  bool
	Target     string
	Fields     []FieldView
	Values     []ConstView
	ValuesFunc string
	Additional *AdditionalView
	Getters    []GetterView
	Union      *UnionView
	Validate   *ValidateView
	Error      *ErrorView
	Mask       *MaskView
}

DeclView is one declaration. Target is the aliased or underlying type, or the base of an enum.

type ErrorView

type ErrorView struct {
	Receiver       string
	Runtime        string
	Path           string
	PathLiteral    string
	Fallback       string
	HasConstructor bool
}

ErrorView is what the Error method and the constructor of an error type need.

type FieldView

type FieldView struct {
	Doc  string
	Name string
	Type string
	Tag  string
}

FieldView is one struct field; Tag is the whole tag literal.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator builds the template data of every models part.

func New

func New(m *gomodel.Model) *Generator

func (*Generator) Parts

func (g *Generator) Parts() []layout.Part

Parts returns every models part, even one without declarations, with the parts its declarations refer to. They share one folder: they often refer to each other in a cycle.

func (*Generator) View

func (g *Generator) View(part layout.PartID, s *gocode.Scope) *PartView

View returns the data part.tmpl renders part from, with types written as the file of s spells them.

type GetterView

type GetterView struct {
	Doc      string
	Receiver string
	Name     string
	Type     string
	Default  string
	Unset    string
	Value    string
}

GetterView is a method that returns Value, or Default when Unset holds.

type LiteralView

type LiteralView struct {
	Type          string
	Runtime       string
	Receiver      string
	IsAnyOf       bool
	IsLiteral     bool
	Discriminator string
	Shared        []string
	Variants      []VariantView
	Also          []LiteralView
}

LiteralView is a runtime.Union literal; Type is empty in Also, Discriminator and Shared quoted.

type LoopView

type LoopView struct {
	Index string
	Item  string
	Range string
	Map   string
	Key   *CheckView
	Check *CheckView
}

LoopView checks each item of a slice, or each key and value of a map in key order. Range is what the loop ranges over, Index and Item its variables, Map the map; Key or Check is nil when unused.

type MaskFieldView

type MaskFieldView struct {
	Target string
	Guard  string
	Value  string
}

MaskFieldView sets Target to Value, Go expressions, when Guard holds or is empty.

type MaskView

type MaskView struct {
	Receiver string
	Mask     string
	Slog     string
	Fields   []MaskFieldView
}

MaskView is what Masked and LogValue need. Mask and Slog are the names of their imports.

type MethodView

type MethodView struct {
	Validation    string
	Counts        []string
	Discriminator string
	Checks        []CheckView
	VariantChecks []CheckView
	Choices       []ChoiceView
}

MethodView is the body of one Validate method; all but Validation and Checks are union checks.

type PartView

type PartView struct {
	Patterns []PatternView
	Decls    []DeclView
}

PartView is the data of one part: the patterns its checks use and its declarations in model order.

type PatternView

type PatternView struct {
	Name   string
	Regexp string
	Source string
}

PatternView is one package-level regular expression.

type ShapeView

type ShapeView struct {
	Required []string
	Known    []string
	HasKnown bool
	IsClosed bool
	IsEmpty  bool
}

ShapeView is a shape quoted as VariantView quotes it; IsEmpty takes any object.

type UnionView

type UnionView struct {
	Receiver    string
	Runtime     string
	JSON        string
	Form        string
	Which       string
	Marshal     string
	IsAnyOf     bool
	IsGrouped   bool
	IsDescribed bool
	IsText      bool
	HasUnion    bool
	Variants    []VariantView
	Args        []string
	Literal     LiteralView
}

UnionView is what a union's variant fields and methods need. Runtime and JSON are the names the packages are imported under, JSON only when shared fields are decoded. IsText adds MarshalText and UnmarshalText; Form, the form type, UnmarshalForm. Which is what decoding sets in doc lines, Marshal the runtime func that writes the variants. IsDescribed uses Args instead.

type ValidateView

type ValidateView struct {
	Receiver   string
	Validation string
	Enum       []string
	Request    MethodView
	Response   *MethodView
}

ValidateView is what the Validate methods of a declaration need. Enum lists the constants an enum takes; Response is set when ValidateResponse checks something else than Validate.

type VariantCheckView

type VariantCheckView struct {
	IsSet string
	Check *CheckView
}

VariantCheckView is one union member; Check is nil when it checks nothing.

type VariantView

type VariantView struct {
	Name      string
	Type      string
	Kinds     []string
	Values    []string
	IsDefault bool
	IsAbsent  bool
	Required  []string
	Known     []string
	HasKnown  bool
	IsClosed  bool
	Shapes    []ShapeView
}

VariantView is one variant field and what decoding needs to know of it. Kinds are runtime.Kind constant names; Values, Required and Known are quoted. HasKnown writes Known even when empty.

Jump to

Keyboard shortcuts

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