modelgen

package
v0.0.0-...-19249b1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrVarMustString = errors.New("variable type must be a string")
	ErrVarNotFound   = errors.New("variable not found")
)

Functions

func DiscoverList

func DiscoverList(list []*ast.Field) []*ast.Field

DiscoverList builds clean lists for ast

func DiscoverNode

func DiscoverNode(node ast.Node) ast.Node

DiscoverType builds clean fields for ast

func DiscoverType

func DiscoverType(express ast.Expr) ast.Expr

DiscoverType builds clean fields for ast

func Ident

func Ident(names ...string) []ast.Expr

func Output

func Output(code string)

func Output2

func Output2(code string)

Types

type FuncDecl

type FuncDecl struct {
	FD *ast.FuncDecl
}

func (*FuncDecl) AddAssignStmt

func (f *FuncDecl) AddAssignStmt(varName []ast.Expr, varToken token.Token, varValue interface{}) *FuncDecl

func (*FuncDecl) AddCallExpr

func (f *FuncDecl) AddCallExpr(funcName string, funcArg ...interface{}) *FuncDecl

func (*FuncDecl) AddComment

func (f *FuncDecl) AddComment(comment string) *FuncDecl

func (*FuncDecl) AddDeclStmt

func (f *FuncDecl) AddDeclStmt(varName, varType string) *FuncDecl

func (*FuncDecl) AddParam

func (f *FuncDecl) AddParam(varName, varType string) *FuncDecl

func (*FuncDecl) AddRecv

func (f *FuncDecl) AddRecv(varName, varType string) *FuncDecl

func (*FuncDecl) AddResult

func (f *FuncDecl) AddResult(varName, varType string) *FuncDecl

func (*FuncDecl) AddReturnStmt

func (f *FuncDecl) AddReturnStmt(funcArg ...interface{}) *FuncDecl

type GenDecl

type GenDecl struct {
	GD *ast.GenDecl
}

func (*GenDecl) AddImport

func (g *GenDecl) AddImport(imp string) *GenDecl

AddImport adds an import

func (*GenDecl) AddVar

func (g *GenDecl) AddVar(varName, varType, varComment string) *GenDecl

AddVar adds a var

type StructChanger

type StructChanger struct {
	Name     string
	Fields   []*ast.Field
	Comments *ast.CommentGroup
	Ok       bool
}

func (*StructChanger) Visit

func (v *StructChanger) Visit(n ast.Node) (w ast.Visitor)

Visit walks the tree for StructChanger

type StructCopier

type StructCopier struct {
	Name     string
	Fields   []*ast.Field
	Comments *ast.CommentGroup
	Ok       bool
}

func (*StructCopier) Visit

func (v *StructCopier) Visit(n ast.Node) (w ast.Visitor)

Visit walks the tree for StructCopier

type Tree

type Tree struct {
	FileSet    *token.FileSet
	File       *ast.File
	CommentMap ast.CommentMap
}

Tree represents a fileset of code

func New

func New(name string) *Tree

New creates a new Go package tree

func ParseFile

func ParseFile(code string) (*Tree, error)

func (*Tree) AddFunc

func (gt *Tree) AddFunc(fd *FuncDecl)

func (*Tree) AddImport

func (gt *Tree) AddImport(gd *GenDecl)

AddImport adds an import section with import paths

func (*Tree) AddImportSection

func (gt *Tree) AddImportSection(imports []string)

AddImport adds an import section with import paths

func (*Tree) AddMainFunc

func (gt *Tree) AddMainFunc()

AddHelloMainFunc adds a main func the outputs: hello world

func (*Tree) AddNewAssignStmt

func (gt *Tree) AddNewAssignStmt(funcName string, varName []ast.Expr, varToken token.Token, varValue interface{}) *Tree

AddNewImport adds an import

func (*Tree) AddNewImport

func (gt *Tree) AddNewImport(imp string) *Tree

AddNewImport adds an import

func (*Tree) AddNewVar

func (gt *Tree) AddNewVar(varName, varType, varComment string) *Tree

AddVar adds a var

func (*Tree) AddVar

func (gt *Tree) AddVar(gd *GenDecl)

AddVar adds a var section

func (*Tree) Bytes

func (gt *Tree) Bytes(doFormat bool) ([]byte, error)

Bytes returns the code as a byte array

func (*Tree) ChangeStruct

func (gt *Tree) ChangeStruct(varName string, varValue []*ast.Field, varComments *ast.CommentGroup) error

ChangeStruct changes the struct field list

func (*Tree) FuncDecl

func (gt *Tree) FuncDecl(name string) *FuncDecl

FuncDecl returns a function declaration

func (*Tree) Import

func (gt *Tree) Import() *GenDecl

Import creates an import section

func (*Tree) ReadVar

func (gt *Tree) ReadVar() (VarRead, error)

StructFields returns the struct fields

func (*Tree) StructFields

func (gt *Tree) StructFields(varName string) ([]*ast.Field, *ast.CommentGroup, error)

StructFields returns the struct fields

func (*Tree) Var

func (gt *Tree) Var() *GenDecl

Var creates a var section

func (*Tree) WriteFile

func (gt *Tree) WriteFile(filepath string, doFormat bool, dirPerm os.FileMode, filePerm os.FileMode) error

WriteFile writes the code to a file and create the folder structure

func (*Tree) WriteVar

func (gt *Tree) WriteVar(sc VarRead) error

ChangeStruct changes the struct field list

type Var

type Var struct {
	Name string
}

Var represents a variable so it's not confused with a string

func Variable

func Variable(v string) Var

Variable returns a variable type

type VarRead

type VarRead struct {
	Comments *ast.CommentGroup
	Expr     *ast.Expr
	Names    []*ast.Ident

	Ok bool
}

func (*VarRead) Visit

func (v *VarRead) Visit(n ast.Node) (w ast.Visitor)

Visit walks the tree

type VarWrite

type VarWrite struct {
	Comments *ast.CommentGroup
	Expr     *ast.Expr
	Names    []*ast.Ident

	Ok bool
}

func (*VarWrite) Visit

func (v *VarWrite) Visit(n ast.Node) (w ast.Visitor)

Visit walks the tree

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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