ast

package
v0.0.0-...-5bba42e Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypePackageApiEnter           = "PackageApiEnter"           // server/api/v1/enter.go
	TypePackageRouterEnter        = "PackageRouterEnter"        // server/router/enter.go
	TypePackageServiceEnter       = "PackageServiceEnter"       // server/service/enter.go
	TypePackageApiModuleEnter     = "PackageApiModuleEnter"     // server/api/v1/{package}/enter.go
	TypePackageRouterModuleEnter  = "PackageRouterModuleEnter"  // server/router/{package}/enter.go
	TypePackageServiceModuleEnter = "PackageServiceModuleEnter" // server/service/{package}/enter.go
	TypePackageInitializeGorm     = "PackageInitializeGorm"     // server/initialize/gorm_biz.go
	TypePackageInitializeRouter   = "PackageInitializeRouter"   // server/initialize/router_biz.go
	TypePluginGen                 = "PluginGen"                 // server/plugin/{package}/gen/main.go
	TypePluginApiEnter            = "PluginApiEnter"            // server/plugin/{package}/enter.go
	TypePluginInitializeV1        = "PluginInitializeV1"        // server/initialize/plugin_biz_v1.go
	TypePluginInitializeV2        = "PluginInitializeV2"        // server/initialize/plugin_biz_v2.go
	TypePluginRouterEnter         = "PluginRouterEnter"         // server/plugin/{package}/enter.go
	TypePluginServiceEnter        = "PluginServiceEnter"        // server/plugin/{package}/enter.go
	TypePluginInitializeApi       = "PluginInitializeApi"       // server/plugin/{package}/initialize/api.go
	TypePluginInitializeGorm      = "PluginInitializeGorm"      // server/plugin/{package}/initialize/gorm.go
	TypePluginInitializeMenu      = "PluginInitializeMenu"      // server/plugin/{package}/initialize/menu.go
	TypePluginInitializeRouter    = "PluginInitializeRouter"    // server/plugin/{package}/initialize/router.go
)

Variables

This section is empty.

Functions

func AddImport

func AddImport(astNode ast.Node, imp string)

AddImport 增加 import 方法

func AddRegisterTablesAst

func AddRegisterTablesAst(path, funcName, pk, varName, dbName, model string)

自动为 gorm.go 注册一个自动迁移

func AddRouterCode

func AddRouterCode(path, funcName, pk, model string)

func AppendNodeToList

func AppendNodeToList(stmts []ast.Stmt, stmt ast.Stmt, index int) []ast.Stmt

func CheckImport

func CheckImport(file *ast.File, importPath string) bool

检查是否存在Import

func CreateApiStructAst

func CreateApiStructAst(apis []system.SysApi) *[]ast.Expr

func CreateMenuStructAst

func CreateMenuStructAst(menus []system.SysBaseMenu) *[]ast.Expr

func CreateStmt

func CreateStmt(statement string) *ast.ExprStmt

func FindArray

func FindArray(astNode ast.Node, identName, selectorExprName string) *ast.CompositeLit

FindArray 查询特定数组方法

func FindFunction

func FindFunction(astNode ast.Node, FunctionName string) *ast.FuncDecl

FindFunction 查询特定function方法

func ImportForAutoEnter

func ImportForAutoEnter(path string, funcName string, code string)

func ImportReference

func ImportReference(filepath, importCode, structName, packageName, groupName string) error

func IsBlockStmt

func IsBlockStmt(node ast.Node) bool

func NeedAppendModel

func NeedAppendModel(callNode ast.Node, pk string, model string) bool

为automigrate增加实参

func RollBackAst

func RollBackAst(pk, model string)

func RollGormBack

func RollGormBack(pk, model string)

func RollRouterBack

func RollRouterBack(pk, model string)

func VariableExistsInBlock

func VariableExistsInBlock(block *ast.BlockStmt, varName string) bool

Types

type Ast

type Ast interface {
	// Parse 解析文件/代码
	Parse(filename string, writer io.Writer) (file *ast.File, err error)
	// Rollback 回滚
	Rollback(file *ast.File) error
	// Injection 注入
	Injection(file *ast.File) error
	// Format 格式化输出
	Format(filename string, writer io.Writer, file *ast.File) error
}

type Base

type Base struct{}

func (*Base) AbsolutePath

func (a *Base) AbsolutePath(filePath string) string

AbsolutePath 相对路径转绝对路径

func (*Base) Format

func (a *Base) Format(filename string, writer io.Writer, file *ast.File) error

func (*Base) Injection

func (a *Base) Injection(file *ast.File) error

func (*Base) Parse

func (a *Base) Parse(filename string, writer io.Writer) (file *ast.File, err error)

func (*Base) RelativePath

func (a *Base) RelativePath(filePath string) string

RelativePath 绝对路径转相对路径

func (*Base) Rollback

func (a *Base) Rollback(file *ast.File) error

type Import

type Import struct {
	Base
	ImportPath string // 导包路径
}

func NewImport

func NewImport(importPath string) *Import

func (*Import) Format

func (a *Import) Format(filename string, writer io.Writer, file *ast.File) error

func (*Import) Injection

func (a *Import) Injection(file *ast.File) error

func (*Import) Parse

func (a *Import) Parse(filename string, writer io.Writer) (file *ast.File, err error)

func (*Import) Rollback

func (a *Import) Rollback(file *ast.File) error

type PackageEnter

type PackageEnter struct {
	Base
	Type              Type   // 类型
	Path              string // 文件路径
	ImportPath        string // 导包路径
	StructName        string // 结构体名称
	PackageName       string // 包名
	RelativePath      string // 相对路径
	PackageStructName string // 包结构体名称
}

PackageEnter 模块化入口

func (*PackageEnter) Format

func (a *PackageEnter) Format(filename string, writer io.Writer, file *ast.File) error

func (*PackageEnter) Injection

func (a *PackageEnter) Injection(file *ast.File) error

func (*PackageEnter) Parse

func (a *PackageEnter) Parse(filename string, writer io.Writer) (file *ast.File, err error)

func (*PackageEnter) Rollback

func (a *PackageEnter) Rollback(file *ast.File) error

type PackageInitializeGorm

type PackageInitializeGorm struct {
	Base
	Type         Type   // 类型
	Path         string // 文件路径
	ImportPath   string // 导包路径
	Business     string // 业务库 gva => gva, 不要传"gva"
	StructName   string // 结构体名称
	PackageName  string // 包名
	RelativePath string // 相对路径
	IsNew        bool   // 是否使用new关键字 true: new(PackageName.StructName) false: &PackageName.StructName{}
}

PackageInitializeGorm 包初始化gorm

func (*PackageInitializeGorm) Format

func (a *PackageInitializeGorm) Format(filename string, writer io.Writer, file *ast.File) error

func (*PackageInitializeGorm) Injection

func (a *PackageInitializeGorm) Injection(file *ast.File) error

func (*PackageInitializeGorm) Parse

func (a *PackageInitializeGorm) Parse(filename string, writer io.Writer) (file *ast.File, err error)

func (*PackageInitializeGorm) Rollback

func (a *PackageInitializeGorm) Rollback(file *ast.File) error

type PackageInitializeRouter

type PackageInitializeRouter struct {
	Base
	Type                 Type   // 类型
	Path                 string // 文件路径
	ImportPath           string // 导包路径
	RelativePath         string // 相对路径
	AppName              string // 应用名称
	GroupName            string // 分组名称
	ModuleName           string // 模块名称
	PackageName          string // 包名
	FunctionName         string // 函数名
	RouterGroupName      string // 路由分组名称
	LeftRouterGroupName  string // 左路由分组名称
	RightRouterGroupName string // 右路由分组名称
}

PackageInitializeRouter 包初始化路由 ModuleName := PackageName.AppName.GroupName ModuleName.FunctionName(RouterGroupName)

func (*PackageInitializeRouter) CreateAssignStmt

func (a *PackageInitializeRouter) CreateAssignStmt() *ast.AssignStmt

func (*PackageInitializeRouter) Format

func (a *PackageInitializeRouter) Format(filename string, writer io.Writer, file *ast.File) error

func (*PackageInitializeRouter) Injection

func (a *PackageInitializeRouter) Injection(file *ast.File) error

func (*PackageInitializeRouter) Parse

func (a *PackageInitializeRouter) Parse(filename string, writer io.Writer) (file *ast.File, err error)

func (*PackageInitializeRouter) Rollback

func (a *PackageInitializeRouter) Rollback(file *ast.File) error

type PackageModuleEnter

type PackageModuleEnter struct {
	Base
	Type         Type   // 类型
	Path         string // 文件路径
	ImportPath   string // 导包路径
	RelativePath string // 相对路径
	StructName   string // 结构体名称
	AppName      string // 应用名称
	GroupName    string // 分组名称
	ModuleName   string // 模块名称
	PackageName  string // 包名
	ServiceName  string // 服务名称
}

PackageModuleEnter 模块化入口 ModuleName := PackageName.AppName.GroupName.ServiceName

func (*PackageModuleEnter) Format

func (a *PackageModuleEnter) Format(filename string, writer io.Writer, file *ast.File) error

func (*PackageModuleEnter) Injection

func (a *PackageModuleEnter) Injection(file *ast.File) error

func (*PackageModuleEnter) Parse

func (a *PackageModuleEnter) Parse(filename string, writer io.Writer) (file *ast.File, err error)

func (*PackageModuleEnter) Rollback

func (a *PackageModuleEnter) Rollback(file *ast.File) error

type PluginEnter

type PluginEnter struct {
	Base
	Type            Type   // 类型
	Path            string // 文件路径
	ImportPath      string // 导包路径
	RelativePath    string // 相对路径
	StructName      string // 结构体名称
	StructCamelName string // 结构体小驼峰名称
	ModuleName      string // 模块名称
	GroupName       string // 分组名称
	PackageName     string // 包名
	ServiceName     string // 服务名称
}

PluginEnter 插件化入口 ModuleName := PackageName.GroupName.ServiceName

func (*PluginEnter) Format

func (a *PluginEnter) Format(filename string, writer io.Writer, file *ast.File) error

func (*PluginEnter) Injection

func (a *PluginEnter) Injection(file *ast.File) error

func (*PluginEnter) Parse

func (a *PluginEnter) Parse(filename string, writer io.Writer) (file *ast.File, err error)

func (*PluginEnter) Rollback

func (a *PluginEnter) Rollback(file *ast.File) error

type PluginGen

type PluginGen struct {
	Base
	Type         Type   // 类型
	Path         string // 文件路径
	ImportPath   string // 导包路径
	RelativePath string // 相对路径
	StructName   string // 结构体名称
	PackageName  string // 包名
	IsNew        bool   // 是否使用new关键字
}

func (*PluginGen) Format

func (a *PluginGen) Format(filename string, writer io.Writer, file *ast.File) error

func (*PluginGen) Injection

func (a *PluginGen) Injection(file *ast.File) error

func (*PluginGen) Parse

func (a *PluginGen) Parse(filename string, writer io.Writer) (file *ast.File, err error)

func (*PluginGen) Rollback

func (a *PluginGen) Rollback(file *ast.File) error

type PluginInitializeGorm

type PluginInitializeGorm struct {
	Base
	Type         Type   // 类型
	Path         string // 文件路径
	ImportPath   string // 导包路径
	RelativePath string // 相对路径
	StructName   string // 结构体名称
	PackageName  string // 包名
	IsNew        bool   // 是否使用new关键字 true: new(PackageName.StructName) false: &PackageName.StructName{}
}

func (*PluginInitializeGorm) Format

func (a *PluginInitializeGorm) Format(filename string, writer io.Writer, file *ast.File) error

func (*PluginInitializeGorm) Injection

func (a *PluginInitializeGorm) Injection(file *ast.File) error

func (*PluginInitializeGorm) Parse

func (a *PluginInitializeGorm) Parse(filename string, writer io.Writer) (file *ast.File, err error)

func (*PluginInitializeGorm) Rollback

func (a *PluginInitializeGorm) Rollback(file *ast.File) error

type PluginInitializeRouter

type PluginInitializeRouter struct {
	Base
	Type                 Type   // 类型
	Path                 string // 文件路径
	ImportPath           string // 导包路径
	ImportGlobalPath     string // 导包全局变量路径
	ImportMiddlewarePath string // 导包中间件路径
	RelativePath         string // 相对路径
	AppName              string // 应用名称
	GroupName            string // 分组名称
	PackageName          string // 包名
	FunctionName         string // 函数名
	LeftRouterGroupName  string // 左路由分组名称
	RightRouterGroupName string // 右路由分组名称
}

PluginInitializeRouter 插件初始化路由 PackageName.AppName.GroupName.FunctionName()

func (*PluginInitializeRouter) Format

func (a *PluginInitializeRouter) Format(filename string, writer io.Writer, file *ast.File) error

func (*PluginInitializeRouter) Injection

func (a *PluginInitializeRouter) Injection(file *ast.File) error

func (*PluginInitializeRouter) Parse

func (a *PluginInitializeRouter) Parse(filename string, writer io.Writer) (file *ast.File, err error)

func (*PluginInitializeRouter) Rollback

func (a *PluginInitializeRouter) Rollback(file *ast.File) error

type PluginInitializeV2

type PluginInitializeV2 struct {
	Base
	Type         Type   // 类型
	Path         string // 文件路径
	PluginPath   string // 插件路径
	RelativePath string // 相对路径
	ImportPath   string // 导包路径
	StructName   string // 结构体名称
	PackageName  string // 包名
}

func (*PluginInitializeV2) Format

func (a *PluginInitializeV2) Format(filename string, writer io.Writer, file *ast.File) error

func (*PluginInitializeV2) Injection

func (a *PluginInitializeV2) Injection(file *ast.File) error

func (*PluginInitializeV2) Parse

func (a *PluginInitializeV2) Parse(filename string, writer io.Writer) (file *ast.File, err error)

func (*PluginInitializeV2) Rollback

func (a *PluginInitializeV2) Rollback(file *ast.File) error

type Type

type Type string

func (Type) Group

func (r Type) Group() string

func (Type) String

func (r Type) String() string

type Visitor

type Visitor struct {
	ImportCode  string
	StructName  string
	PackageName string
	GroupName   string
}

func (*Visitor) Visit

func (vi *Visitor) Visit(node ast.Node) ast.Visitor

Jump to

Keyboard shortcuts

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