generation

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrParserUnknownDecl = errors.New("definition files can only contain package, import, var and func declarations")

ErrParserUnknownDecl is the Parser error for unknown declarations.

View Source
var ErrParserVarDecl = errors.New("var declaration contains an error")

ErrParserVarDecl is the Parser error for invalid var declarations.

Functions

This section is empty.

Types

type DICopier

type DICopier struct {
	// Output is where the repository should be copied.
	Output string
	// Box contains the di files.
	Box packr.Box
}

DICopier is able to copy the github.com/sarulabs/di repository. The files are in github.com/sarulabs/dingo/generation/di.

func NewDICopier

func NewDICopier(loc *Locator, subdir string, box packr.Box) *DICopier

NewDICopier is the DICopier constructor.

func (*DICopier) Copy

func (c *DICopier) Copy() error

Copy copies github.com/sarulabs/di in the destination directory.

type DeclarationList

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

DeclarationList is the structure used to store the name of the declarations in the source files. A declaration is the name of the variable containing one or more dingo.Def.

func NewDeclarationList

func NewDeclarationList() *DeclarationList

NewDeclarationList is the DeclarationList constructor.

func (*DeclarationList) Add

func (dl *DeclarationList) Add(name string) error

Add adds a new declaration in the DeclarationList.

func (*DeclarationList) Merge

func (dl *DeclarationList) Merge(declList *DeclarationList) error

Merge adds the declarations of the declList to the DeclarationList.

func (*DeclarationList) String

func (dl *DeclarationList) String(prefix, sep string) string

String turns the declarations into a string. It works like strings.Join on the declaration names, but it also allows to add a prefix before each element.

type DefinitionCopier

type DefinitionCopier struct {
	Locator *Locator
	SubDir  string
}

DefinitionCopier copies the definition files from the source directory, to the destination directory. It changes the package name in the files.

func NewDefinitionCopier

func NewDefinitionCopier(loc *Locator, subDir string) *DefinitionCopier

NewDefinitionCopier is the DefinitionCopier constructor.

func (*DefinitionCopier) Copy

func (cop *DefinitionCopier) Copy() error

Copy copies each source file in the destination directory.

type Generator

type Generator struct {
	Locator      *Locator
	Box          packr.Box
	Declarations *DeclarationList
}

Generator creates the compiler files and runs the compiler. It generates the dependency injection container.

func NewGenerator

func NewGenerator(loc *Locator, box packr.Box, decls *DeclarationList) *Generator

NewGenerator is the Generator constructor.

func (*Generator) Run

func (gen *Generator) Run() error

Run executes the Generator.

type Locator

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

Locator provides an easy way to get information about the source and destination directories.

func NewLocator

func NewLocator(src, dest string) (*Locator, error)

NewLocator creates an initialized Locator.

func (*Locator) DestDir

func (l *Locator) DestDir() string

DestDir returns the absolute path to the destination directory. Init should be called first.

func (*Locator) DestPkg

func (l *Locator) DestPkg() string

DestPkg returns the name of the package for the files in the destination directory. Init should be called first.

func (*Locator) Init

func (l *Locator) Init(src, dest string) error

Init initialize the Locator instance with a given source and destination directories. dest must be in the $GOPATH.

func (*Locator) SourceDir

func (l *Locator) SourceDir() string

SourceDir returns the absolute path to the source directory. Init should be called first.

func (*Locator) SourceDirName

func (l *Locator) SourceDirName() string

SourceDirName returns the name of the source directory. Init should be called first.

func (*Locator) SourceFiles

func (l *Locator) SourceFiles() []string

SourceFiles returns the name of the go files contained in the source directory. Init should be called first.

type Parser

type Parser struct {
	Locator *Locator
}

Parser can find the definition declarations in the source files.

func NewParser

func NewParser(loc *Locator) *Parser

NewParser is the Parser constructor.

func (*Parser) Parse

func (p *Parser) Parse() (*DeclarationList, error)

Parse finds the definition declarations in the source files. It may also return an error if the package name of the source file does not match the name of its directory.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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