-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildDog.go
65 lines (51 loc) · 1.06 KB
/
buildDog.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"os"
"path/filepath"
"runtime"
"strconv"
)
var version int = 1
var (
flPort int
flDir string
flSignKey string
)
var workingDir string
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.IntVar(&flPort, "port", 8808, "server port")
flag.StringVar(&flDir, "dir", os.TempDir(), "building dir")
flag.StringVar(&flSignKey, "key", "", "Sign GPG key")
}
func initWorkingDir() {
_, err := os.Stat(workingDir)
if err == nil || (err != nil && os.IsExist(err)) {
// WorkingDir exists
if err := os.RemoveAll(workingDir); err != nil {
panic("Remove working dir error")
}
goto create
}
if err != nil && os.IsNotExist(err) {
goto create
} else {
panic("stat working dir error")
}
create:
if err := os.MkdirAll(workingDir, 0755); err != nil {
panic("mkdir working dir error")
}
}
func main() {
flag.Parse()
if flSignKey == "" {
flag.Usage()
}
workingDir = filepath.Join(flDir, "BuildDog", strconv.Itoa(version))
initWorkingDir()
initTaskPool()
serv := newAPIServer()
panic(serv.ListenAndServe())
}