Documentation ¶
Index ¶
- Constants
- Variables
- func IsDefaultPackageTpl(name string) bool
- func MapSerializer(serializer string) string
- func SetDefaultTemplateConfig()
- type Backend
- type Client
- 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() error
- func (routerNode *RouterNode) FindNearest(paths []string) (*RouterNode, int)
- func (routerNode *RouterNode) Insert(name string, method *HttpMethod, handlerType string, paths []string, ...)
- func (routerNode *RouterNode) Sort()
- func (routerNode *RouterNode) Update(method *HttpMethod, handlerType, handlerPkg string) error
- type Service
- 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"
)
Variables ¶
View Source
var DefaultDelimiters = [2]string{"{{", "}}"}
Functions ¶
func IsDefaultPackageTpl ¶ added in v0.5.1
func MapSerializer ¶
func SetDefaultTemplateConfig ¶
func SetDefaultTemplateConfig()
Types ¶
type ClientFile ¶ added in v0.5.0
type ClientMethod ¶ added in v0.5.0
type CustomizedFileForIDL ¶ added in v0.5.1
type CustomizedFileForIDL struct { *IDLPackageRenderInfo FilePath string FilePackage string }
type CustomizedFileForMethod ¶ added in v0.5.1
type CustomizedFileForMethod struct { *HttpMethod FilePath string FilePackage string ServiceInfo *Service // service info for that method }
type CustomizedFileForService ¶ added in v0.5.1
type CustomizedFileForService struct { *Service FilePath string FilePackage string IDLPackageInfo *IDLPackageRenderInfo // IDL info for that service }
type FilePathRenderInfo ¶ added in v0.5.1
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 ReturnTypeName string Path string Serializer string OutputDir string // Annotations map[string]string Models map[string]*model.Model }
func (*HttpMethod) InitComment ¶
func (m *HttpMethod) InitComment()
type HttpPackage ¶
type HttpPackageGenerator ¶
type HttpPackageGenerator struct { ConfigPath string Backend meta.Backend Options []Option CmdType string ProjPackage string HandlerDir string RouterDir string ModelDir string UseDir string ClientDir string IdlClientDir string ForceClientDir string NeedModel bool HandlerByMethod bool BaseDomain string TemplateGenerator // contains filtered or unexported fields }
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 ¶ added in v0.5.1
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 ¶ added in v0.6.0
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 MiddleWare string Path string 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() error
DyeGroupName traverses the routing tree in depth and names the middleware for each node.
func (*RouterNode) FindNearest ¶
func (routerNode *RouterNode) FindNearest(paths []string) (*RouterNode, int)
func (*RouterNode) Insert ¶
func (routerNode *RouterNode) Insert(name string, method *HttpMethod, handlerType string, paths []string, handlerPkg string)
func (*RouterNode) Sort ¶
func (routerNode *RouterNode) Sort()
func (*RouterNode) Update ¶
func (routerNode *RouterNode) Update(method *HttpMethod, handlerType, handlerPkg string) error
type Service ¶
type Service struct { Name string Methods []*HttpMethod ClientMethods []*ClientMethod Models []*model.Model // all dependency models BaseDomain string // base domain for client code }
type Template ¶
type Template struct { Default bool // Update command behavior; skip/cover/append 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 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 ¶ added in v0.5.1
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 }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.