Finding imports and dependencies of a go program -


the go list -json command run command line tell imports , dependencies of go program ( in json format). there way information within go program i.e @ runtime, either running 'go list' command somehow or way?

i don't think can without using go binary since go needs analyze source code.

it's pretty easy must have access go , source code @ run time. heres quick example:

package main  import (     "encoding/json"     "fmt"     "os/exec" )  func main() {     cmd := exec.command("go", "list", "-json")     stdout, err := cmd.output()     if err != nil {         println(err.error())         return     }      var list golist     err = json.unmarshal(stdout, &list)      _, d := range list.deps {         fmt.printf(" - %s\n", d)     } }  type golist struct {     dir        string     importpath string     name       string     target     string     stale      bool     root       string     gofiles    []string     imports    []string     deps       []string } 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -