Get a module file path

package main
import (
func main() {

I use go module for this, the package is downloaded to ~/go/pkg/mod/

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}}' ""

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.