docs: readme

This commit is contained in:
xuthus5 2023-06-22 01:08:09 +08:00
parent 875a73a463
commit 83050b0d3b
Signed by: xuthus5
GPG Key ID: A23CF9620CBB55F9
2 changed files with 33 additions and 2 deletions

View File

@ -8,4 +8,36 @@
- 获取所有的常量定义
- 获取所有的函数定义
- 获取所有的结构体定义
- 获取所有的方法定义
- 获取所有的方法定义
## 用例
```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")
```

1
go.mod
View File

@ -7,6 +7,5 @@ require github.com/stretchr/testify v1.8.1
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)