A small package that helps you parse Go files by annotation in doc comment, e.g. get var values or list of struct methods.
Features:
- get values of variables:
- literal types
- slices of literal types
- maps with literal types as keys and values
- get list of function names:
- by method receiver type
- by parameters types
Literal types:
-
bool
-
string
-
int8-int64
-
uint8-uint64
-
float32/64
— set directly, w/o type castings or pointers
Usage:
parsed code:
var (
// parser
boolValue = true
// parser:str
stringValue = "3"
main code:
import (
gp "github.com/goiste/goparser"
)
...
p, err := gp.New("example_code.go")
if err != nil {
panic(err)
}
boolValues := gp.GetBasicValues[bool](p, "parser")
for _, v := range boolValues {
fmt.Printf("name: %s; value: %t\n", v.Name, v.Value) // name: boolValue; value: true
}
stringValues := gp.GetBasicValues[string](p, "parser", "parser:str")
for _, v := range stringValues {
fmt.Printf("name: %s; value: %q\n", v.Name, v.Value) // name: stringValue; value: "3"
}