generator

package
v0.0.0-...-4aae350 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RegisterFile = "router_gen.go"
)

Variables

View Source
var DefaultDelimiters = [2]string{"{{", "}}"}

Functions

func IsDefaultTpl

func IsDefaultTpl(name string) bool

func MapSerializer

func MapSerializer(serializer string) string

func SetDefaultTemplateConfig

func SetDefaultTemplateConfig()

Types

type Backend

type Backend interface {
	Template() (*template.Template, error)
	List() map[string]string
	SetOption(opts string) error
	GetOptions() []string
	Funcs(name string, fn interface{}) error
}

type Client

type Client struct {
	Handler
	ServiceName string
}

type File

type File struct {
	Path        string
	Content     string
	NoRepeat    bool
	FileTplName string
}

func (*File) Lint

func (file *File) Lint() error

Lint is used to statically analyze and format go code

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

func (*GolangBackend) Template

func (gb *GolangBackend) Template() (*template.Template, error)

type Handler

type Handler struct {
	FilePath    string
	PackageName string
	Imports     map[string]*model.Model
	Methods     []*HttpMethod
}

func (*Handler) Format

func (h *Handler) Format()

type HttpMethod

type HttpMethod struct {
	Name            string
	HTTPMethod      string
	Comment         string
	RequestTypeName string
	ReturnTypeName  string
	Path            string
	Serializer      string
	// Annotations     map[string]string
	Models map[string]*model.Model
}

func (*HttpMethod) InitComment

func (m *HttpMethod) InitComment()

type HttpPackage

type HttpPackage struct {
	IdlName  string
	Package  string
	Services []*Service
	Models   []*model.Model
}

type HttpPackageGenerator

type HttpPackageGenerator struct {
	ConfigPath  string
	Backend     meta.Backend
	Options     []Option
	ProjPackage string
	HandlerDir  string
	RouterDir   string
	ModelDir    string
	ClientDir   string
	NeedModel   bool

	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 Layout

type Layout struct {
	GoModule        string
	ServiceName     string
	UseApacheThrift bool
	HasIdl          bool
}

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 Option

type Option string
const (
	OptionMarshalEnumToText  Option = "MarshalEnumToText"
	OptionTypedefAsTypeAlias Option = "TypedefAsTypeAlias"
)

type RegisterDependency

type RegisterDependency struct {
	PkgAlias string
	Pkg      string
}

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}}
	HttpMethod string
}

func NewRouterTree

func NewRouterTree() *RouterNode

NewRouterTree contains "/" as root node

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)

func (*RouterNode) Sort

func (routerNode *RouterNode) Sort()

func (*RouterNode) Update

func (routerNode *RouterNode) Update(method *HttpMethod, handlerType string) error

type Service

type Service struct {
	Name    string
	Methods []*HttpMethod
	Models  []*model.Model // all dependency models
}

type Template

type Template struct {
	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
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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