codegen

package
v0.0.0-...-42b6e8f Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2016 License: ISC Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractArgs

func ExtractArgs(ctx *Context, stp *ast.StructType, name string) ([]string, error)

ExtractArgs parses the arguments out of a template invocation, using the invoking fields tags.

func ExtractTemplatesFromType

func ExtractTemplatesFromType(
	ctx *Context,
	stp *ast.StructType,
) (result []string, err error)

ExtractTemplatesFromType returns a slice of templates that have been invoked upon the provided struct.

func Output

func Output(ctx *Context, p string, data string) error

Output writes a new file at `p` using `data`

func Process

func Process(arg string, searchPath []string) error

Process runs the code gen engine against `arg` using `searchPath` to lookup templates.

func ProcessDir

func ProcessDir(dir string, searchPath []string) error

ProcessDir runs the code gen engine against all files in `dir` using `searchPath` to lookup templates.

func ProcessFilePath

func ProcessFilePath(p string, searchPath []string) error

ProcessFilePath runs the code gen engine against a single file, at `p` using `searchPath` to lookup templates.

func RunTemplate

func RunTemplate(ctx *Context, templateName string, typeName string, st *ast.StructType) error

Types

type Context

type Context struct {
	Dir         string
	SearchPaths []string
	Fset        *token.FileSet
	Templates   map[string]*template.Template
	PackageName string
	Imports     map[string]bool
	Results     map[string]string
}

Context represents the context in which a code generation operation is run.

func NewContext

func NewContext(dir string, searchPaths []string) (*Context, error)

NewContext initializes a new code generation context.

func (*Context) Populate

func (ctx *Context) Populate() error

Populate fills in the rest of the context based upon the context's config.

type TemplateContext

type TemplateContext struct {
	Name         string
	TemplateName string
	PackageName  string
	Ctx          *Context
	Struct       *ast.StructType
}

func (*TemplateContext) AddImport

func (mc *TemplateContext) AddImport(name string) string

func (*TemplateContext) Args

func (mc *TemplateContext) Args() []string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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