Documentation
¶
Overview ¶
Package models defines the domain models that model field relations and manipulation.
Index ¶
- Constants
- type Field
- func (f *Field) AllFields(fields []*Field, cyclic map[*Field]bool) []*Field
- func (f *Field) FullDefinition() string
- func (f *Field) FullName(name string) string
- func (f *Field) FullNameWithoutPointer(name string) string
- func (f *Field) FullVariableName(name string) string
- func (f *Field) IsArray() bool
- func (f *Field) IsChan() bool
- func (f *Field) IsCollection() bool
- func (f *Field) IsComposite() bool
- func (f *Field) IsContainer() bool
- func (f *Field) IsFunc() bool
- func (f *Field) IsInterface() bool
- func (f *Field) IsMap() bool
- func (f *Field) IsPointer() bool
- func (f *Field) IsSlice() bool
- func (f *Field) IsStruct() bool
- func (f *Field) IsType() bool
- func (f *Field) String() string
- func (f *Field) UsesPointer() bool
- type FieldOptions
- type Function
- type FunctionOptions
- type Generator
- type GeneratorOptions
- type Type
Constants ¶
const ( ContainerStruct = "struct" ContainerInterface = "interface" )
Container refers to a category of types which indicate that a field contains multiple fields.
const ( CollectionPointer = "*" CollectionSlice = "[]" CollectionMap = "map" CollectionChan = "chan" CollectionFunc = "func" )
Collection refers to a category of types which indicate that a field's definition collects multiple fields (i.e `map[string]bool`).
const Pointer = "*"
Pointer represents the string representation of a pointer.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
// VariableName represents name that is used to assign the field.
//
// This value will always be unique in the context of the application.
// TypeField variable names do not contain '.' (i.e 'tA' in 'tA.UserID').
// Field variable names are defined by their specifier (i.e '.UserID' in 'domain.Account.UserID').
VariableName string
// Import represents the file that field was imported from.
Import string
// Package represents the package the field is defined in (i.e `log` in `log.Logger`).
Package string
// Name represents the name of the field (i.e `ID` in `ID int`).
Name string
// Definition represents the type definition of the field (i.e `int` in `ID int`, `Logger` in `log.Logger`).
Definition string
// Pointer represents the pointer of this field (i.e `*`).
Pointer string
// Container represents the container that this field represents.
//
// A container (in the domain of field manipulation) refers to a
// category of types which indicate that a field contains multiple fields.
//
// a "struct" collection contains subfields with any other type.
// an "interface" collection contains `func` subfields.
Container string
// The tags defined in a struct field (i.e `json:"tag,omitempty"`)
// map[tag]map[name][]options (i.e map[json]map[tag]["omitempty"])
Tags map[string]map[string][]string
// The type or field that contains this field.
Parent *Field
// The field that this field will be copied from (or nil).
// Set in the matcher.
From *Field
// The field that this field will be copied to (or nil).
// Set in the matcher.
To *Field
// The fields of this field.
Fields []*Field
// The custom options of a field.
Options FieldOptions
}
Field represents a field to be copied to/from. A field's struct properties are set in the parser unless its stated otherwise.
func (*Field) AllFields ¶ added in v0.2.0
AllFields gets all the fields in the scope of a field (including itself).
func (*Field) FullDefinition ¶ added in v0.3.1
FullDefinition returns the full definition of a field including its package.
func (*Field) FullName ¶ added in v0.2.0
FullName returns the full name of a field including its parents (i.e *domain.Account.User.ID).
func (*Field) FullNameWithoutPointer ¶ added in v0.3.2
FullNameWithoutContainer returns the full name of a field including its parents without the container (i.e domain.Account.User.ID).
func (*Field) FullVariableName ¶ added in v0.2.0
FullVariableName returns the full variable name of a field (i.e tA.User.UserID).
func (*Field) IsCollection ¶ added in v0.3.2
IsCollection returns whether the field is a collection.
func (*Field) IsComposite ¶ added in v0.3.2
IsComposite returns whether the field is a composite type: array, slice, map, chan.
func (*Field) IsContainer ¶ added in v0.3.2
IsContainer returns whether the field has a container.
func (*Field) IsInterface ¶ added in v0.3.0
isInterface returns whether the field is an interface.
func (*Field) UsesPointer ¶ added in v0.3.2
UsesPointer returns whether the field uses a pointer.
type FieldOptions ¶
type FieldOptions struct {
// The function the field is converted with (as a parameter).
Convert string
// The field to map this field to, if any.
Map string
// The tag to map this field with, if any.
Tag string
// The level at which sub-fields are discovered.
Depth int
// Whether the field should be explicitly automatched.
Automatch bool
// Whether the field should be deepcopied.
Deepcopy bool
}
FieldOptions represent options for a Field.
type Function ¶
type Function struct {
Name string // The name of the function.
Options FunctionOptions // The custom options of a function.
From []Type // The types to copy fields from.
To []Type // The types to copy fields to.
}
Function represents the properties of a generated function.
type FunctionOptions ¶
type FunctionOptions struct {
Custom map[string][]string // The custom options of a function (map[option]values).
Manual bool // Whether the function uses a manual matcher (as opposed to an Automatcher).
}
FunctionOptions represent options for a Function.
type Generator ¶
type Generator struct {
Functions []Function // The functions to generate.
Options GeneratorOptions // The custom options for the generator.
Loadpath string // The filepath the loader file is located in.
Setpath string // The filepath the setup file is located in.
Outpath string // The filepath the generated code is output to.
Tempath string // The filepath for the template used to generate code.
Keep []byte // The code that is kept from the setup file.
}
Generator represents a code generator.
type GeneratorOptions ¶ added in v0.2.0
type GeneratorOptions struct {
Custom map[string]interface{} // The custom options of a generator.
}
GeneratorOptions represent options for a Generator.