gen_apiV2

package
v0.0.0-...-62aa942 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const CasbinMark string = "@Casbin"
View Source
const GenMark string = "@GenApi"
View Source
const NGForm = "ngform"

Variables

View Source
var Indent = "  "
View Source
var JsonInterface *types.Interface

Functions

func CheckJsonImplements

func CheckJsonImplements(ctx *DepthContext, node ast.Node) *ast.Ident

func Convert

func Convert(s string) string

func DepthType

func DepthType(ctx *DepthContext) ast.Node

func FindImportPath

func FindImportPath(importSpecs []*ast.ImportSpec, target string) string

func FindPkgBySelector

func FindPkgBySelector(pkg *packages.Package, file *ast.File, selector *ast.SelectorExpr) *packages.Package

func FindStructByExpr

func FindStructByExpr(pkg *packages.Package, file *ast.File, expr ast.Expr) (*packages.Package, *ast.File, *ast.TypeSpec, *ast.StructType)

func FindStructTypeByName

func FindStructTypeByName(pkg *packages.Package, structName string) (*ast.File, *ast.TypeSpec, *ast.StructType)

func FindTypeByName

func FindTypeByName(pkg *packages.Package, TypeName string) (*ast.File, *ast.TypeSpec)

func FormConvert

func FormConvert(s string) string

func GetFileNameByPos

func GetFileNameByPos(fset *token.FileSet, pos token.Pos) string

func IsSelector

func IsSelector(field *ast.Field) (string, string, bool)

判断是否是selecter类型

func JudgeBuiltInType

func JudgeBuiltInType(t string) bool

go 的内置基础类型

func LoadPackages

func LoadPackages(dir string) (string, *packages.Package, *token.FileSet)

func MatchPathParam

func MatchPathParam(s string) []string

func NGTAG

func NGTAG(s string) ngTag

func Node2String

func Node2String(fset *token.FileSet, node interface{}) string

func Node2SwagType

func Node2SwagType(node ast.Node, selectName string) ast.Node

type Req struct { 转换部分 xxx.Client Name Client }

func SelectorCover

func SelectorCover(expr *ast.SelectorExpr) *ast.Ident

func SpliceType

func SpliceType(pkg *packages.Package, file *ast.File, node ast.Node) bool

func Struct2Ts

func Struct2Ts(pkg *packages.Package, file *ast.File, node ast.Node, objName string) string

func ToImportRawPath

func ToImportRawPath(importSpecs []*ast.ImportSpec) []string

print "fmt.print"

func ToTs

func ToTs(pkg *packages.Package, file *ast.File, node ast.Node, format func(string) string) []string

func TrimImport

func TrimImport(s string) string

func WarpResult2Ts

func WarpResult2Ts(pkg *packages.Package, file *ast.File, node ast.Node, objName string) string

Types

type ApiContext

type ApiContext struct {
	PkgName      string
	Fset         *token.FileSet
	Pkg          *packages.Package
	Files        map[string]*FileContext
	ReginsterMap map[string][]Func
}

func NewApiContext

func NewApiContext() *ApiContext

func (*ApiContext) FuncsToMapByRouterGroupKey

func (c *ApiContext) FuncsToMapByRouterGroupKey()

func (*ApiContext) Load

func (c *ApiContext) Load(dir string)

func (*ApiContext) Parse

func (c *ApiContext) Parse(option ParseOption)

type Bind

type Bind struct {
	Uri struct {
		Has     bool
		Param   []string
		TagMsgs []TagMsg
	}
	Body struct {
		Has            bool
		QuoteType      QuoteType
		Comment        string
		SwagStructName string
		SwagRaw        string
		SwagObj        string
	}
	Query struct {
		Has            bool
		QuoteType      QuoteType
		Comment        string
		SwagStructName string
		SwagRaw        string
		SwagObj        string
	}
	Header struct {
		Has     bool
		TagMsgs []TagMsg
	}
	CtxKey struct {
		Has bool
	}
}

type DepthContext

type DepthContext struct {
	Pkg  *packages.Package
	File *ast.File
	Node ast.Node
}

func NewDepthContext

func NewDepthContext(pkg *packages.Package, file *ast.File, node ast.Node) *DepthContext

type ExtractStruct2Ts

type ExtractStruct2Ts struct {
	PendNodeRecord  map[string]struct{}
	PendNodes       []NodeInfo
	ResolveNodes    []NodeInfo
	ResolveMergePkg map[string]struct{}
	TempNodeInfo    NodeInfo
	EnterType       NodeInfo
}

func NewExtractStruct2Ts

func NewExtractStruct2Ts(pkg *packages.Package, file *ast.File, node ast.Node, pendNodeRecord map[string]struct{}) *ExtractStruct2Ts

func (*ExtractStruct2Ts) AddPendNodes

func (e *ExtractStruct2Ts) AddPendNodes(pkg *packages.Package, file *ast.File, node *ast.TypeSpec) bool

func (*ExtractStruct2Ts) MergePkg

func (e *ExtractStruct2Ts) MergePkg(pkg *packages.Package)

func (*ExtractStruct2Ts) Parse

func (e *ExtractStruct2Ts) Parse()

func (*ExtractStruct2Ts) Pend2Temp

func (e *ExtractStruct2Ts) Pend2Temp() bool

func (*ExtractStruct2Ts) SpliceType

func (e *ExtractStruct2Ts) SpliceType() bool

func (*ExtractStruct2Ts) SpliceTypeV2

func (e *ExtractStruct2Ts) SpliceTypeV2() bool

func (*ExtractStruct2Ts) Temp2ResolveNodes

func (e *ExtractStruct2Ts) Temp2ResolveNodes()

func (*ExtractStruct2Ts) ToTs

func (e *ExtractStruct2Ts) ToTs(format func(string) string) []string

type FileContext

type FileContext struct {
	PkgName              string
	Pkg                  *packages.Package
	File                 *ast.File
	CasbinInterfaceType1 *types.Interface
	CasbinInterfaceType2 *types.Interface
	//ImportMsgs map[string]ImportMsg
	Funcs []Func
}

func NewFileContext

func NewFileContext(pkgName string, pkg *packages.Package, file *ast.File) *FileContext

func (*FileContext) ApiMark2SwagRouter

func (c *FileContext) ApiMark2SwagRouter(fields []string) (Router, string)

func (*FileContext) FilterFunc

func (c *FileContext) FilterFunc() []*ast.FuncDecl

func (*FileContext) Func2Ts

func (c *FileContext) Func2Ts()

func (*FileContext) GinFormat

func (c *FileContext) GinFormat(f *ast.FuncDecl) bool

GinFormat 符合 func Name(c *gin.context, in object) (out object, err error)

func (*FileContext) HasApiMark

func (c *FileContext) HasApiMark(doc *ast.CommentGroup) bool

HasApiMark 注释包含@GenApi的才符合规范

func (*FileContext) Parse

func (c *FileContext) Parse(option ParseOption)

func (*FileContext) ParseBind

func (c *FileContext) ParseBind(inPkg *packages.Package, inFile *ast.File, funcName string, structType *ast.StructType) Bind

func (*FileContext) ParseComment

func (c *FileContext) ParseComment(fc *Func, ms []*ast.Comment, inField *ast.Field, outField *ast.Field)

func (*FileContext) ParseFunc

func (c *FileContext) ParseFunc(f *ast.FuncDecl) Func

func (*FileContext) Struct2Quote

func (c *FileContext) Struct2Quote(fset *token.FileSet, field *ast.Field) string

type Func

type Func struct {
	Fd         *ast.FuncDecl
	NeedImport []string
	PkgName    string
	Comments   []string
	Router     Router
	FuncName   string
	Bind       Bind
	ParamIn1   string
	ParamIn1Ts []string
	ResOut0    string
	ResOut0Ts  []string
	Plugins    Plugins
}

type ImportMsg

type ImportMsg struct {
	Dir       string
	AliseName string
	PkgName   string
}

type NodeInfo

type NodeInfo struct {
	Pkg  *packages.Package
	File *ast.File
	Node ast.Node
}

type ParseOption

type ParseOption struct {
	ParseTs bool
}

type Plugins

type Plugins struct {
	Point    []plugins.PointTemplate
	CallBack plugins.CallBackTemplate
}

type QuoteType

type QuoteType string
const IdentType QuoteType = "ident"
const StructType QuoteType = "struct"

type Router

type Router struct {
	Method         string
	GenMarkPath    string
	GinPath        string
	TsPath         string
	RouterGroupKey string
}

type Set

type Set struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet() *Set

func (*Set) Add

func (s *Set) Add(sets ...Seter)

func (*Set) Get

func (s *Set) Get() []interface{}

type Seter

type Seter interface {
	GetKey() string
}

type TagMsg

type TagMsg struct {
	TagValue string
	Comment  string
}

func FindTagAndCommentByField

func FindTagAndCommentByField(pkg *packages.Package, file *ast.File, field *ast.Field, TagName string) []TagMsg

func FindTagAndCommentByStruct

func FindTagAndCommentByStruct(pkg *packages.Package, file *ast.File, structType *ast.StructType, tagName string) []TagMsg

func FindTagByType

func FindTagByType(pkg *packages.Package, file *ast.File, ty ast.Node, tagName string) []TagMsg

Directories

Path Synopsis
ui

Jump to

Keyboard shortcuts

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