Go to file
xuthus5 af09de2e00
fix: go mod path
2023-06-24 22:18:28 +08:00
testdata fix: nil pointer 2023-03-18 23:17:09 +08:00
.gitignore first commit 2023-01-01 16:38:14 +08:00
README.md docs: readme 2023-06-22 01:08:09 +08:00
go.mod fix: go mod path 2023-06-24 22:18:28 +08:00
go.sum fix: go mod path 2023-06-24 22:18:28 +08:00
goast.go fix: nil pointer 2023-03-18 23:17:09 +08:00
goast_test.go fix: go mod path 2023-06-24 22:18:28 +08:00
util.go fix: nil pointer 2023-03-18 23:17:09 +08:00

README.md

GOAST

GoAst 是一个go文件解析器

提供能力:

  • 获取所有的变量定义
  • 获取所有的常量定义
  • 获取所有的函数定义
  • 获取所有的结构体定义
  • 获取所有的方法定义

用例

package main

import
gitter.top/coco/goast

func
func main() {
    parser, err := NewParser("hello.go")
    if err != nil {
        // do something
    }
    defines, err := parser.Parse()
    if err != nil {
        // do something
    }
    // 是否存在变量Hello
    defines.ExistVariable("Hello")
    // 是否存在常量 World
    defines.ExistConstant("World")
    // 是否存在函数 Add
    defines.ExistFunction("Add")
    // 是否存在Calc结构体的方法 Sub
    defines.ExistMethod("Calc.Sub")
    // 是否存在导入包 "a/b/c"
    defines.ExistImport("a/b/c")
    // 是否存在结构体定义 Calc
    defines.ExistType("Calc")