loader

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package loader loads generator information from an external file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountFields

func CountFields(fields []*models.Field) int

CountFields returns the number of fields in a field slice.

func DefineFieldsByFrom

func DefineFieldsByFrom(from *From, toType *models.Type, fromType *models.Type) ([]*models.Field, []*models.Field)

DefineFieldsByFrom defines fields for a to-type and from-type based on a YML from. Used when the user specifies the fields to match in the loader.

func LoadYML

func LoadYML(filepath string) (*models.Generator, error)

LoadYML loads a .yml file into a Generator.

func PrintFieldGraph

func PrintFieldGraph(fields []*models.Field, tabs string)

PrintFieldGraph prints a list of fields with the related fields.

func PrintFieldRelation

func PrintFieldRelation(toFields []*models.Field, fromFields []*models.Field)

PrintFieldRelation prints the relationship between to and from fields.

func PrintFieldTree

func PrintFieldTree(typename string, fields []*models.Field, tabs string)

PrintFieldTree prints a tree of fields for a given type to standard output.

func PrintFunctionFields

func PrintFunctionFields(function models.Function)

PrintFunctionFields prints all of a functions fields to standard output.

Types

type AST

type AST struct {
	Depth    int // The current depth level of the ASTSearcher.
	MaxDepth int // The maximum depth of the ASTSearcher.
	// contains filtered or unexported fields
}

AST uses Abstract Syntax Tree analysis to find fields.

func (*AST) Automatch

func (a *AST) Automatch(toType *models.Type, fromType *models.Type) ([]*models.Field, []*models.Field, error)

Automatch uses an AST to automatically match the fields of a toType by name. Used when no field options are specified in the loader.

func (*AST) Search

func (a *AST) Search(imprt string, pkg string, typename string) ([]*models.Field, error)

Search searches a .go source file for a type and its fields using an Abstract Syntax Tree.

type Field

type Field struct {
	To       string                 `yaml:"to"`
	Convert  string                 `yaml:"convert"`
	Deepcopy string                 `yaml:"deepcopy"`
	Options  map[string]interface{} `yaml:"options"`
}

Field represents the field properties of the YML file.

type From

type From struct {
	Package  string                 `yaml:"package"`
	Import   string                 `yaml:"import"`
	Fields   map[string]Field       `yaml:"fields"`
	Pointer  bool                   `yaml:"pointer"`
	Depth    int                    `yaml:"depth"`
	Deepcopy string                 `yaml:"deepcopy"`
	Options  map[string]interface{} `yaml:"options"`
}

From represents from-type properties in the YML file.

type Function

type Function struct {
	To      map[string]To          `yaml:"to"`
	From    map[string]From        `yaml:"from"`
	Options map[string]interface{} `yaml:"options"`
}

Function represents function properties of the YML file.

type Parser

type Parser struct {
	YML       YML              // The YML that is parsed.
	AST       AST              // The Abstract Syntax Tree object used during matching.
	Generator models.Generator // The generator that information is parsed to.

}

Parser represents a YML parser that loads properties into the program models.

func (*Parser) ParseYML

func (p *Parser) ParseYML() (*models.Generator, error)

ParseYML parses a YML into a Generator.

type To

type To struct {
	Package  string                 `yaml:"package"`
	Import   string                 `yaml:"import"`
	Pointer  bool                   `yaml:"pointer"`
	Depth    int                    `yaml:"depth"`
	Deepcopy string                 `yaml:"deepcopy"`
	Options  map[string]interface{} `yaml:"options"`
}

To represents to-type properties in the YML file.

type YML

type YML struct {
	Generated map[string]interface{} `yaml:"generated"`
	Import    []string               `yaml:"import"`
	Functions map[string]Function    `yaml:"functions"`
}

YML represents the first level of the YML file.

Jump to

Keyboard shortcuts

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