github.com/lmittmann/w3@v0.20.0/internal/mod/root.go (about)

     1  package mod
     2  
     3  import (
     4  	"os/exec"
     5  	"strings"
     6  )
     7  
     8  // Root contains the absolute path of the module root. Its value is empty if
     9  // used outside of a module.
    10  var Root string
    11  
    12  func init() {
    13  	stdout, _ := exec.Command("go", "env", "GOMOD").Output()
    14  
    15  	var ok bool
    16  	Root, ok = strings.CutSuffix(strings.TrimSpace(string(stdout)), "/go.mod")
    17  	if !ok {
    18  		Root = ""
    19  	}
    20  }