Documentation ¶
Index ¶
- Constants
- Variables
- func IsDefaultPackageTpl(name string) bool
- func MapSerializer(serializer string) string
- func SetDefaultTemplateConfig()
- type Backend
- type Client
- type ClientConfig
- type ClientFile
- type ClientMethod
- type CustomizedFileForIDL
- type CustomizedFileForMethod
- type CustomizedFileForService
- type File
- type FilePathRenderInfo
- type GolangBackend
- type Handler
- type HttpMethod
- type HttpPackage
- type HttpPackageGenerator
- type IDLPackageRenderInfo
- type Layout
- type LayoutGenerator
- type Option
- type RegisterInfo
- type Router
- type RouterNode
- func (routerNode *RouterNode) DFS(i int, hook func(layer int, node *RouterNode) error) error
- func (routerNode *RouterNode) DyeGroupName(snakeStyleMiddleware bool) error
- func (routerNode *RouterNode) FindNearest(paths []string, method string, sortRouter bool) (*RouterNode, int)
- func (routerNode *RouterNode) Insert(name string, method *HttpMethod, handlerType string, paths []string, ...)
- func (routerNode *RouterNode) RawHandlerName() string
- func (routerNode *RouterNode) Sort()
- func (routerNode *RouterNode) Update(method *HttpMethod, handlerType, handlerPkg string, sortRouter bool) error
- type Service
- type SingleHandler
- type Template
- type TemplateConfig
- type TemplateGenerator
- func (tg *TemplateGenerator) Degenerate() error
- func (tg *TemplateGenerator) Files() []File
- func (tg *TemplateGenerator) Generate(input interface{}, tplName, filepath string, noRepeat bool) error
- func (tg *TemplateGenerator) GetFormatAndExcludedFiles() ([]File, error)
- func (tg *TemplateGenerator) Init() error
- func (tg *TemplateGenerator) Persist() error
- type UpdateBehavior
Constants ¶
View Source
const ( Skip = "skip" Cover = "cover" Append = "append" )
View Source
const (
RegisterFile = "router_gen.go"
)
View Source
const ServiceSuffix = "Service"
Variables ¶
View Source
var DefaultDelimiters = [2]string{"{{", "}}"}
Functions ¶
func IsDefaultPackageTpl ¶
func MapSerializer ¶
func SetDefaultTemplateConfig ¶
func SetDefaultTemplateConfig()
Types ¶
type ClientConfig ¶
type ClientConfig struct {
QueryEnumAsInt bool
}
type ClientFile ¶
type ClientFile struct { Config ClientConfig FilePath string PackageName string ServiceName string BaseDomain string Imports map[string]*model.Model ClientMethods []*ClientMethod }
type ClientMethod ¶
type CustomizedFileForIDL ¶
type CustomizedFileForIDL struct { *IDLPackageRenderInfo FilePath string FilePackage string }
type CustomizedFileForMethod ¶
type CustomizedFileForMethod struct { *HttpMethod FilePath string FilePackage string ServiceInfo *Service // service info for this method IDLPackageInfo *IDLPackageRenderInfo // IDL info for this service }
type CustomizedFileForService ¶
type CustomizedFileForService struct { *Service FilePath string FilePackage string IDLPackageInfo *IDLPackageRenderInfo // IDL info for this service }
type FilePathRenderInfo ¶
type FilePathRenderInfo struct { MasterIDLName string // master IDL name GenPackage string // master IDL generate code package HandlerDir string // handler generate dir ModelDir string // model generate dir RouterDir string // router generate dir ProjectDir string // projectDir GoModule string // go module ServiceName string // service name, changed as services are traversed MethodName string // method name, changed as methods are traversed HandlerGenPath string // "api.gen_path" value }
type GolangBackend ¶
type GolangBackend struct{}
func (*GolangBackend) Funcs ¶
func (gb *GolangBackend) Funcs(name string, fn interface{}) error
func (*GolangBackend) GetOptions ¶
func (gb *GolangBackend) GetOptions() []string
func (*GolangBackend) List ¶
func (gb *GolangBackend) List() map[string]string
func (*GolangBackend) SetOption ¶
func (gb *GolangBackend) SetOption(opts string) error
type Handler ¶
type HttpMethod ¶
type HttpMethod struct { Name string HTTPMethod string Comment string RequestTypeName string RequestTypePackage string RequestTypeRawName string ReturnTypeName string ReturnTypePackage string ReturnTypeRawName string Path string Serializer string OutputDir string RefPackage string // handler import dir RefPackageAlias string // handler import alias ModelPackage map[string]string GenHandler bool // Whether to generate one handler, when an idl interface corresponds to multiple http method // Annotations map[string]string Models map[string]*model.Model }
func (*HttpMethod) InitComment ¶
func (m *HttpMethod) InitComment()
type HttpPackage ¶
type HttpPackageGenerator ¶
type HttpPackageGenerator struct { ServiceGroup string ConfigPath string // package template path Backend meta.Backend // model template Options []Option CmdType string ProjPackage string // go module for project HandlerDir string RouterDir string ModelDir string UseDir string // model dir for third repo ClientDir string // client dir for "new"/"update" command IdlClientDir string // client dir for "client" command ForceClientDir string // client dir without namespace for "client" command BaseDomain string // request domain for "client" command QueryEnumAsInt bool // client code use number for query parameter ServiceGenDir string NeedModel bool HandlerByMethod bool // generate handler files with method dimension SnakeStyleMiddleware bool // use snake name style for middleware SortRouter bool ForceUpdateClient bool // force update 'crafter_client.go' TemplateGenerator // contains filtered or unexported fields }
HttpPackageGenerator is used to record the configuration related to generating crafter http code.
func (*HttpPackageGenerator) GenModel ¶
func (pkgGen *HttpPackageGenerator) GenModel(data *model.Model, gen bool) error
func (*HttpPackageGenerator) Generate ¶
func (pkgGen *HttpPackageGenerator) Generate(pkg *HttpPackage) error
func (*HttpPackageGenerator) Init ¶
func (pkgGen *HttpPackageGenerator) Init() error
func (*HttpPackageGenerator) LoadBackend ¶
func (pkgGen *HttpPackageGenerator) LoadBackend(backend meta.Backend) error
type IDLPackageRenderInfo ¶
type IDLPackageRenderInfo struct { FilePathRenderInfo ServiceInfos *HttpPackage }
type Layout ¶
type Layout struct { OutDir string GoModule string ServiceName string UseApacheThrift bool HasIdl bool NeedGoMod bool ModelDir string HandlerDir string RouterDir string }
Layout contains the basic information of idl
type LayoutGenerator ¶
type LayoutGenerator struct { ConfigPath string TemplateGenerator }
LayoutGenerator contains the information generated by generating the layout template
func (*LayoutGenerator) Degenerate ¶
func (lg *LayoutGenerator) Degenerate() error
func (*LayoutGenerator) Generate ¶
func (lg *LayoutGenerator) Generate(data map[string]interface{}) error
func (*LayoutGenerator) GenerateByConfig ¶
func (lg *LayoutGenerator) GenerateByConfig(configPath string) error
func (*LayoutGenerator) GenerateByService ¶
func (lg *LayoutGenerator) GenerateByService(service Layout) error
func (*LayoutGenerator) Init ¶
func (lg *LayoutGenerator) Init() error
type RegisterInfo ¶
type Router ¶
type Router struct { FilePath string PackageName string HandlerPackages map[string]string // {{basename}}:{{import_path}} Router *RouterNode }
type RouterNode ¶
type RouterNode struct { GroupName string // current group name(the parent middleware name), used to register route. example: {{.GroupName}}.{{HttpMethod}} MiddleWare string // current node middleware, used to be group name for children. HandlerMiddleware string GroupMiddleware string PathPrefix string Path string Parent *RouterNode Children childrenRouterInfo Handler string // {{HandlerPackage}}.{{HandlerName}} HandlerPackage string HandlerPackageAlias string HttpMethod string }
func (*RouterNode) DFS ¶
func (routerNode *RouterNode) DFS(i int, hook func(layer int, node *RouterNode) error) error
func (*RouterNode) DyeGroupName ¶
func (routerNode *RouterNode) DyeGroupName(snakeStyleMiddleware bool) error
DyeGroupName traverses the routing tree in depth and names the handler/group middleware for each node. If snakeStyleMiddleware is set to true, the name style of the middleware will use snake name style.
func (*RouterNode) FindNearest ¶
func (routerNode *RouterNode) FindNearest(paths []string, method string, sortRouter bool) (*RouterNode, int)
func (*RouterNode) Insert ¶
func (routerNode *RouterNode) Insert(name string, method *HttpMethod, handlerType string, paths []string, handlerPkg string, sortRouter bool)
func (*RouterNode) RawHandlerName ¶
func (routerNode *RouterNode) RawHandlerName() string
func (*RouterNode) Sort ¶
func (routerNode *RouterNode) Sort()
func (*RouterNode) Update ¶
func (routerNode *RouterNode) Update(method *HttpMethod, handlerType, handlerPkg string, sortRouter bool) error
type Service ¶
type Service struct { Name string Version string Methods []*HttpMethod ClientMethods []*ClientMethod Models []*model.Model // all dependency models BaseDomain string // base domain for client code ServiceGroup string // service level router group ServiceGenDir string // handler_dir for handler_by_service }
type SingleHandler ¶
type SingleHandler struct { *HttpMethod FilePath string PackageName string ProjPackage string }
type Template ¶
type Template struct { Default bool // Is it the default template Path string `yaml:"path"` // The generated path and its filename, such as biz/handler/ping.go Delims [2]string `yaml:"delims"` // Template Action Instruction Identifier, default: "{{}}" Body string `yaml:"body"` // Render template, currently only supports go template syntax Disable bool `yaml:"disable"` // Disable generating file, used to disable default package template LoopMethod bool `yaml:"loop_method"` // Loop generate files based on "method" LoopService bool `yaml:"loop_service"` // Loop generate files based on "service" UpdateBehavior UpdateBehavior `yaml:"update_behavior"` // Update command behavior; 0:unchanged, 1:regenerate, 2:append }
type TemplateConfig ¶
type TemplateConfig struct {
Layouts []Template `yaml:"layouts"`
}
type TemplateGenerator ¶
type TemplateGenerator struct { OutputDir string Config *TemplateConfig Excludes []string // contains filtered or unexported fields }
TemplateGenerator contains information about the output template
func (*TemplateGenerator) Degenerate ¶
func (tg *TemplateGenerator) Degenerate() error
func (*TemplateGenerator) Files ¶
func (tg *TemplateGenerator) Files() []File
func (*TemplateGenerator) Generate ¶
func (tg *TemplateGenerator) Generate(input interface{}, tplName, filepath string, noRepeat bool) error
func (*TemplateGenerator) GetFormatAndExcludedFiles ¶
func (tg *TemplateGenerator) GetFormatAndExcludedFiles() ([]File, error)
func (*TemplateGenerator) Init ¶
func (tg *TemplateGenerator) Init() error
func (*TemplateGenerator) Persist ¶
func (tg *TemplateGenerator) Persist() error
type UpdateBehavior ¶
type UpdateBehavior struct { Type string `yaml:"type"` // Update behavior type: skip/cover/append // the following variables are used for append update AppendKey string `yaml:"append_key"` // Append content based in key; for example: 'method'/'service' InsertKey string `yaml:"insert_key"` // Insert content by "insert_key" AppendTpl string `yaml:"append_content_tpl"` // Append content if UpdateBehavior is "append" ImportTpl []string `yaml:"import_tpl"` // Import insert template AppendLocation string `yaml:"append_location"` // AppendLocation specifies the location of append, the default is the end of the file }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.