-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathglobal.go
More file actions
54 lines (44 loc) · 932 Bytes
/
global.go
File metadata and controls
54 lines (44 loc) · 932 Bytes
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
51
52
53
54
package accipfs
import (
"fmt"
"os"
"os/exec"
"strings"
)
// DefaultPath ...
var DefaultPath = "."
var _env []string
// CheckPort ...
func CheckPort(port int) error {
checkStatement := fmt.Sprintf("netstat -anp | grep -q %d ", port)
output, err := exec.Command("sh", "-c", checkStatement).CombinedOutput()
if err != nil {
return nil
}
if len(output) > 0 {
return fmt.Errorf("port %d already occupied", port)
}
return nil
}
// Environ ...
func Environ() []string {
if _env == nil {
return os.Environ()
}
return _env
}
// RegisterPathEnv ...
func RegisterPathEnv(paths ...string) {
path := ""
if len(paths) > 1 {
path = strings.Join(paths, string(os.PathListSeparator))
} else if len(paths) == 1 {
path = paths[0]
} else {
return
}
if err := os.Setenv("PATH", strings.Join([]string{os.Getenv("PATH"), path}, string(os.PathListSeparator))); err != nil {
panic(err)
}
_env = os.Environ()
}