Documentation
¶
Index ¶
- Constants
- func ApplyMeta(outdir string, meta *TemplateMeta, data interface{}, dftName string) (*os.File, error)
- func CppFormat(filename string) error
- func GeneratePackage(pkg *build.Package) (files map[string]bool, err error)
- func GoFmt(filename string) error
- func Init(buildType BuildTypeFunc, plugin build.Plugin, config build.PluginRuntimeConfig)
- func OpenTemplatesDir(lang, dir string) ([]os.FileInfo, error)
- func ParseTemplateFile(filename string) (*TemplateMeta, *Template, error)
- func ParseTemplateFilename(filename string) (kind, suffix string)
- type Bean
- type BuildTypeFunc
- type Context
- type File
- type GenDecl
- type Package
- type Template
- type TemplateMeta
Constants ¶
const ( // IncludesDir contains template files for `include` and `include_template` functions IncludesDir = "includes" // TemplateFileSuffix is the template filename suffix could be recognized TemplateFileSuffix = ".temp" )
Variables ¶
This section is empty.
Functions ¶
func ApplyMeta ¶
func ApplyMeta(outdir string, meta *TemplateMeta, data interface{}, dftName string) (*os.File, error)
ApplyMeta creates a target file by the template meta
func GeneratePackage ¶
GeneratePackage generates codes for package
func Init ¶
func Init( buildType BuildTypeFunc, plugin build.Plugin, config build.PluginRuntimeConfig, )
Init initializes generator NOTE: You MUST initialize generator before using generator
buildType is a function for building build.Type to a string plugin is the language plugin config is runtime config of the plugin
func OpenTemplatesDir ¶
OpenTemplatesDir opens a directory for getting all files and directories
func ParseTemplateFile ¶
func ParseTemplateFile(filename string) (*TemplateMeta, *Template, error)
ParseTemplateFile parses template file
func ParseTemplateFilename ¶
ParseTemplateFilename parses template filename: <kind>[.suffix][.flags].temp `kind` maybe `package`,`file`,`const` and other bean kinds like `struct`,`protocol`,`service` etc. Examples:
struct.go.temp -> (struct, go) struct.h.temp -> (struct, h) struct.cpp.temp -> (struct, cpp) struct.cpp.1.temp -> (struct, cpp)
Types ¶
type Bean ¶
Bean wraps build.Bean
type BuildTypeFunc ¶
BuildTypeFunc is a function type which used to build `build.Type` to a string
type Context ¶
type Context struct {
// Pkg represents current package
Pkg *build.Package
// Root represents root template
Root *Template
// Plugin represents current plugin
Plugin build.Plugin
// Config represents current plugin runtime config
Config build.PluginRuntimeConfig
// Kind holds current template kind
Kind string
// contains filtered or unexported fields
}
Context holds current context for generating codes of specified package
func NewContext ¶
func NewContext( buildType BuildTypeFunc, plugin build.Plugin, config build.PluginRuntimeConfig, ) *Context
NewContext creates a context by buildType,plugin,plugin_config
func (*Context) AutoGenDeclaration ¶
AutoGenDeclaration returns a declaration which would be written to each generated file header e.g. // AUTO-GENERATED by midc!! DON'T EDIT!!
type Template ¶
Template wraps template.Template
func NewTemplate ¶
NewTemplate creates a Template by template.Template
type TemplateMeta ¶
TemplateMeta represents meta information of a template file