parse_go

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GoToPBMapping = map[string]string{
	"int":     "int64",
	"float":   "double",
	"int16":   "int32",
	"float16": "double",
	"float64": "double",
	"float32": "float",
	"int32":   "int32",
	"int64":   "int64",
	"uint32":  "uint32",
	"uint64":  "uint64",
	"bool":    "bool",
	"string":  "string",
	"[]byte":  "bytes",
}

Functions

func AddCheck

func AddCheck(checkFuncs ...CheckFunc) options.Option

AddCheck 添加后续校验信息

func AddParseFunc

func AddParseFunc(parseDocs ...ParseFunc) options.Option

AddParseFunc 添加自定义解析Func

func AddParseStruct

func AddParseStruct(parseTag ...ParseStruct) options.Option

AddParseStruct 添加自定义解析struct内容

func GoTypeToPB

func GoTypeToPB(s string) string

GoTypeToPB go type 转化成 pb type

func IsMappingKey

func IsMappingKey(key string) bool

IsMappingKey 判断是否是 pb map的key类型

func ParseGo

func ParseGo(filepath string, options ...options.Option) (gparser.Parser, error)

Types

type CheckFunc

type CheckFunc func(g *GoParsePB) error

type File

type File struct {
	Tag    string // Tag: 字段的tag标记
	Name   string // Name: 字段名
	TypeGo string // TypeGo: 字段的原始类型
	TypePB string // TypePB: 字段在proto中的类型
}

File 字段信息

func CreateFile

func CreateFile(tag string, name string, tGo string, tPb string) *File

CreateFile 创建字段信息

type GoParsePB

type GoParsePB struct {
	PkgName      string            // PkgName: 包名
	FilePath     string            // FilePath: 文件的路径
	Server       []*Server         // Server: 解析出来function的信息
	Message      []*Message        // Message: 解析出struct的信息
	Note         []*Note           // Note: 其他注释
	Metas        map[string]string // Metas: 其他元信息
	ParseStructs []ParseStruct
	ParseFuncS   []ParseFunc
	CheckFuncS   []CheckFunc
}

GoParsePB .go 文件转成 pb文件

func CreateGoParsePB

func CreateGoParsePB(pkgName string, filepath string, notes []*Note) *GoParsePB

CreateGoParsePB 创建 GoParsePB Metas

func (*GoParsePB) AddMessages

func (g *GoParsePB) AddMessages(messages ...*Message)

AddMessages 添加message信息

func (*GoParsePB) AddNotes

func (g *GoParsePB) AddNotes(notes ...*Note)

func (*GoParsePB) AddServers

func (g *GoParsePB) AddServers(servers ...*Server)

AddServers 添加server信息

func (*GoParsePB) Generate

func (g *GoParsePB) Generate() string

Generate 生成pb文件

func (*GoParsePB) Messages

func (g *GoParsePB) Messages() []*Message

Messages 返回解析后的所有Message对象

func (*GoParsePB) Notes

func (g *GoParsePB) Notes() []*Note

Notes 获取注释消息

func (*GoParsePB) PackageName

func (g *GoParsePB) PackageName() string

PackageName 返回包名

func (*GoParsePB) PileDismantle

func (g *GoParsePB) PileDismantle(clearCode string) error

func (*GoParsePB) PileDriving

func (g *GoParsePB) PileDriving(functionName string, startNotes, endNotes string, insertCode string) error

PileDriving 源文件打桩 functionName: 指定函数内打桩,选传 startNotes,endNotes: 可以传两个打桩点,startNotes,endNotes中必填一个 insertCode: 插入代码段

func (*GoParsePB) Servers

func (g *GoParsePB) Servers() []*Server

Servers 返回解析后的所有Server对象

type Message

type Message struct {
	Pos   int            // Pos: struct的起始字节位置
	End   int            // End: struct的结束字节为止
	Name  string         // Name: struct name
	Files []*File        // Files: 字段信息
	Notes []*ast.Comment // Notes: struct的注释信息,用于埋点打桩
}

Message Message对应struct

func CreateMessage

func CreateMessage(name string, pos, end int) *Message

CreateMessage 创建Message

func (*Message) AddFiles

func (m *Message) AddFiles(files ...*File)

AddFiles 添加字段信息

type Note

type Note struct {
	IsUse bool // 判断作用域, 如果是 struct中 或者 func中代表已经使用
	*ast.Comment
}

type ParseFunc

type ParseFunc func(server *Server)

type ParseStruct

type ParseStruct func(file *File)

type Server

type Server struct {
	Pos             int            // Pos: 函数的起始字节位置
	End             int            // End: 函数的结束字节为止
	Name            string         // Name: 函数名
	ServerName      string         // ServerName: server name 通过 parseFunc 绑定
	Method          string         // Method: method 通过 parseFunc 绑定
	Router          string         // Router: router 通过 parseFunc 绑定
	InputParameter  string         // InputParameter: 入参
	OutputParameter string         // OutputParameter: 出参
	Doc             []string       // Doc: 函数注释信息,可以通过自定义的 parseFunc 去进行解析
	Notes           []*ast.Comment // Notes: 函数中的注释信息,用于埋点打桩

}

Server Server对应Go func

func CreateServer

func CreateServer(name string, pos, end int, doc []string, inputParameter string, outputParameter string) *Server

CreateServer 创建Server

Jump to

Keyboard shortcuts

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