Get a module file path

package main
import (
	"github.com/qor/admin"
)
func main() {
}

I use go module for this, the package github.com/qor/admin is downloaded to ~/go/pkg/mod/github.com/qor/admin@v0.0.0-20201015070726-29e78837de93/

how can i get this path programmatically ?

You shouldn’t need to and I’m not aware of a way to get that information. Especially as the location might not be available anymore at runtime.

i can get it with

go list -f '{{.Dir}}' "github.com/qor/admin"

but i want to get it with go code (except os.Exec way)

Why exactly do you need it? It’s not guaranteed to be available at runtime!

The packages code will be statically linked into your application and then you can move the program to other hosts which do not even need to have go installed.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.