github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/helper/subproc/self.go (about) 1 package subproc 2 3 import ( 4 "fmt" 5 "os" 6 "os/exec" 7 "strings" 8 ) 9 10 var ( 11 // executable is the executable of this process 12 executable string 13 ) 14 15 func init() { 16 s, err := os.Executable() 17 if err != nil { 18 panic(fmt.Sprintf("failed to detect executable: %v", err)) 19 } 20 21 // when running tests, we need to use the real nomad binary, 22 // and make sure you recompile between changes! 23 if strings.HasSuffix(s, ".test") { 24 if s, err = exec.LookPath("nomad"); err != nil { 25 panic(fmt.Sprintf("failed to find nomad binary: %v", err)) 26 } 27 } 28 executable = s 29 } 30 31 // Self returns the path to the executable of this process. 32 func Self() string { 33 return executable 34 }