-
Notifications
You must be signed in to change notification settings - Fork 11
/
go.go
50 lines (39 loc) · 770 Bytes
/
go.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"os"
"os/exec"
"strings"
)
func goGet(dir string, importPath ...string) error {
if len(importPath) == 0 {
return nil
}
cmd := []string{"get", "-d", "-t"}
cmd = append(cmd, importPath...)
c := newGoCmd(cmd...)
c.Dir = dir
return c.Run()
}
func runGoCmd(args ...string) error {
c := newGoCmd(args...)
return c.Run()
}
func newGoCmd(args ...string) *exec.Cmd {
c := exec.Command("go", args...)
c.Env = goCmdEnv()
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
return c
}
func goCmdEnv() []string {
return append(envNoGopath(), "GOPATH="+setting.WorkDir())
}
func envNoGopath() (a []string) {
for _, s := range os.Environ() {
if !strings.HasPrefix(s, "GOPATH=") {
a = append(a, s)
}
}
return a
}