I'm looking for a library that should parse a go source code and returns the list of identifies related to the Go's standard library. For instance, after processing the following code:
package main
import (
"os"
"os/signal"
"syscall"
)
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGUSR2)
}
the output should resemble something like: os: Signal: 1 os/signal: Notify: 1 syscall: SIGINT: 1, SIGUSR2: 1
I’m not sure what you want to do specifically, but generally a list of tokens isn’t particularly useful. Generally you want to look at walking an AST (Abstract Syntax Tree) which gives you most of the same information within a more meaningful context. For this you probably want to look at the go/ast
and go/parser
standard library packages should give you most of what you want.