github.com/cilium/cilium@v1.16.2/tools/dev-doctor/common.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package main 5 6 import ( 7 "go/build" 8 "os" 9 "os/exec" 10 ) 11 12 // sudo returns cmd run with sudo. cmd is modified in place. 13 func sudo(cmd *exec.Cmd) (*exec.Cmd, error) { 14 sudoPath, err := exec.LookPath("sudo") 15 if err != nil { 16 return nil, err 17 } 18 cmd.Args = append([]string{cmd.Path}, cmd.Args...) 19 cmd.Path = sudoPath 20 return cmd, nil 21 } 22 23 // goPath returns the environment $GOPATH, or the default when empty or unset. 24 func goPath() string { 25 if gp := os.Getenv("GOPATH"); gp != "" { 26 return gp 27 } 28 return build.Default.GOPATH 29 }