|
@ -6,6 +6,7 @@ import ( |
|
|
"io" |
|
|
"io" |
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"os" |
|
|
"os" |
|
|
|
|
|
"os/exec" |
|
|
"os/signal" |
|
|
"os/signal" |
|
|
"path/filepath" |
|
|
"path/filepath" |
|
|
"strings" |
|
|
"strings" |
|
@ -13,9 +14,22 @@ import ( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
|
GoPath = os.Getenv("GOPATH") |
|
|
|
|
|
|
|
|
GoPath = gopath() |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func gopath() string { |
|
|
|
|
|
path := os.Getenv("GOPATH") |
|
|
|
|
|
if len(path) == 0 { |
|
|
|
|
|
goCmd := exec.Command("go", "env", "GOPATH") |
|
|
|
|
|
out, err := goCmd.Output() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(fmt.Sprintf("failed to determine gopath: %v", err)) |
|
|
|
|
|
} |
|
|
|
|
|
path = string(out) |
|
|
|
|
|
} |
|
|
|
|
|
return path |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func TrapSignal(cb func()) { |
|
|
func TrapSignal(cb func()) { |
|
|
c := make(chan os.Signal, 1) |
|
|
c := make(chan os.Signal, 1) |
|
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM) |
|
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM) |
|
|