Documentation
¶
Overview ¶
Package goast is a library for parsing Go code and extracting information from it.
Index ¶
- Constants
- func ParseStruct(body string) (map[string]*StructInfo, error)
- func ParseStructMethods(astInfos []*AstInfo) map[string][]*MethodInfo
- type AstInfo
- type CodeAst
- func MergeGoCode(srcCode []byte, genCode []byte, opts ...CodeAstOption) (*CodeAst, error)
- func MergeGoFile(srcFile string, genFile string, opts ...CodeAstOption) (*CodeAst, error)
- func NewCodeAst(filePath string, opts ...CodeAstOption) (*CodeAst, error)
- func NewCodeAstFromData(data []byte, opts ...CodeAstOption) (*CodeAst, error)
- type CodeAstOption
- type ConstInfo
- type FuncInfo
- type ImportInfo
- type InterfaceInfo
- type MethodInfo
- type StructFieldInfo
- type StructInfo
- type TypeInfo
- type VarInfo
Constants ¶
const ( PackageType = "package" ImportType = "import" ConstType = "const" VarType = "var" FuncType = "func" TypeType = "type" StructType = "struct" InterfaceType = "interface" ArrayType = "array" MapType = "map" ChanType = "chan" )
Variables ¶
This section is empty.
Functions ¶
func ParseStruct ¶
func ParseStruct(body string) (map[string]*StructInfo, error)
ParseStruct parse struct info from source code
func ParseStructMethods ¶
func ParseStructMethods(astInfos []*AstInfo) map[string][]*MethodInfo
ParseStructMethods parse struct methods from ast infos
Types ¶
type AstInfo ¶
type AstInfo struct { // Type is the type of the code block, such as "func", "type", "const", "var", "import", "package". Type string // Names is the name of the code block, such as "func Name", "type Names", "const Names", "var Names", "import Paths". // If Type is "func", a standalone function without a receiver has a single name. // If the function is a method belonging to a struct, it has two names: the first // represents the function name, and the second represents the struct name. Names []string Comment string Body string }
AstInfo Go code block information
func ParseGoCode ¶
ParseGoCode parses a go code and returns a list of AstInfo
func (*AstInfo) IsConstType ¶
func (*AstInfo) IsFuncType ¶
func (*AstInfo) IsImportType ¶
func (*AstInfo) IsPackageType ¶
func (*AstInfo) IsTypeType ¶
type CodeAst ¶
type CodeAst struct { FilePath string Code string AstInfos []*AstInfo // contains filtered or unexported fields }
CodeAst is the struct for code
func MergeGoCode ¶
func MergeGoCode(srcCode []byte, genCode []byte, opts ...CodeAstOption) (*CodeAst, error)
MergeGoCode merges two Go code strings into one.
func MergeGoFile ¶
func MergeGoFile(srcFile string, genFile string, opts ...CodeAstOption) (*CodeAst, error)
MergeGoFile merges two Go code files into one.
func NewCodeAst ¶
func NewCodeAst(filePath string, opts ...CodeAstOption) (*CodeAst, error)
NewCodeAst creates a new CodeAst object from file path
func NewCodeAstFromData ¶
func NewCodeAstFromData(data []byte, opts ...CodeAstOption) (*CodeAst, error)
NewCodeAstFromData creates a new CodeAst object from data
type CodeAstOption ¶
type CodeAstOption func(*CodeAst)
func WithCoverSameFunc ¶
func WithCoverSameFunc() CodeAstOption
WithCoverSameFunc sets cover same function in the merged code
func WithIgnoreMergeFunc ¶
func WithIgnoreMergeFunc(funcName ...string) CodeAstOption
WithIgnoreMergeFunc sets ignore to merge the same function name in the two code
type ConstInfo ¶
func ParseConstGroup ¶
ParseConstGroup parse const group from source code
type FuncInfo ¶
FuncInfo represents function information
func FilterFuncCode ¶
FilterFuncCode filters out the code of functions that contain panic("implement me") or customized flag, e.g. panic("ai to do")
func FilterFuncCodeByFile ¶
FilterFuncCodeByFile filters out the code of functions that contain panic("implement me") or customized flag, e.g. panic("ai to do")
func (FuncInfo) ExtractComment ¶
ExtractComment extracts function comments in Go code
type ImportInfo ¶
func ParseImportGroup ¶
func ParseImportGroup(body string) ([]*ImportInfo, error)
ParseImportGroup parse import group from source code
type InterfaceInfo ¶
type InterfaceInfo struct { Name string Comment string MethodInfos []*MethodInfo }
func ParseInterface ¶
func ParseInterface(body string) ([]*InterfaceInfo, error)
ParseInterface parse interface group from source code
type MethodInfo ¶
MethodInfo method function info
type StructFieldInfo ¶
type StructInfo ¶
type StructInfo struct { Name string Comment string Fields []*StructFieldInfo }
type TypeInfo ¶
func ParseTypeGroup ¶
ParseTypeGroup parse type group from source code