lib

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EngineName = "e"
	Tips       = `` /* 342-byte string literal not displayed */

	TemplateFile = `
	package _example

	import (
		"github.com/gin-gonic/gin"
	)

	func Route(e *gin.Engine) {
	}`
)

Variables

View Source
var (
	DefaultFileName = "route.entry.go"
)

Functions

func AddImport

func AddImport(f *ast.File, im string)

func GenAssign

func GenAssign(path, pPath string, mids *[]MWTuple) *ast.AssignStmt

func GenTemplate

func GenTemplate() *ast.File

func Generate

func Generate(dirList ...string)

Generate the entry function of project

func TraverseRawFuncList

func TraverseRawFuncList(list *[]RawFunc, h *[]HandlerFunc, m map[string]*MiddlewareFunc, i map[string]bool)

TraverseRawFuncList traverses list of RawFunc and get handler list ,middleware map and imports list

func WalkFileTree

func WalkFileTree(from *FileTreeNode, to *[]RawFunc)

WalkFileTree walk file tree and get the raw function

Types

type FileTreeNode

type FileTreeNode struct {
	PackagePath string
	Files       map[string]*ast.File
	Children    []*FileTreeNode
}

func LoadFileTree

func LoadFileTree(dir string) *FileTreeNode

LoadFileTree load disk file into a tree

func NewEmptyFileTree

func NewEmptyFileTree() *FileTreeNode

type Func

type Func interface {
	ParseRawFunc() Func
}

type GenContext

type GenContext struct {
	Root       *GroupTree
	MiddlePool map[string]*MiddlewareFunc
	GroupPool  map[string]*GroupTree
}

func (*GenContext) InitGroupTree

func (ctx *GenContext) InitGroupTree(middles map[string]*MiddlewareFunc, handles *[]HandlerFunc)

InitGroupTree with middlewares and handlers

func (*GenContext) PutHandler

func (ctx *GenContext) PutHandler(h *HandlerFunc)

func (*GenContext) PutMiddleware

func (ctx *GenContext) PutMiddleware(m *MiddlewareFunc)

type GroupTree

type GroupTree struct {
	Path     string // /c
	AbsPath  string // /aaa/bbb/c
	Ctx      *GenContext
	Parent   *GroupTree
	Middles  []MWTuple
	Handlers []*HandlerFunc
	Children map[string]*GroupTree
}

func NewGroupTreeNode

func NewGroupTreeNode(path, absPath string, ctx *GenContext, parent *GroupTree) *GroupTree

func (*GroupTree) GenAST

func (node *GroupTree) GenAST() []ast.Stmt

type HandlerFunc

type HandlerFunc struct {
	RawFunc
	Group        *GroupTree
	GroupArray   []string // /user -> /name
	Need         []string // middleware id
	Middles      []*MiddlewareFunc
	Method       string
	RelativePath string
}

func (*HandlerFunc) GenAST

func (h *HandlerFunc) GenAST() *ast.ExprStmt

type MWTuple

type MWTuple struct {
	M *MiddlewareFunc
	W int
}

type MiddlewareFunc

type MiddlewareFunc struct {
	RawFunc
	ID    string
	Group map[string]int
}

type RawFunc

type RawFunc struct {
	Comment     string
	PackagePath string
	Package     string
	Signature   string
}

func (RawFunc) ParseRawFunc

func (f RawFunc) ParseRawFunc() Func

ParseRawFunc generate Func from RawFunc

Jump to

Keyboard shortcuts

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