-
Notifications
You must be signed in to change notification settings - Fork 63
/
g.go
89 lines (75 loc) · 1.77 KB
/
g.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"encoding/json"
"flag"
"log"
"os"
"runtime"
"strconv"
"strings"
"gopkg.in/mgo.v2"
)
// Web UI default Listen address
var G_AlexHost = "0.0.0.0"
var G_AlexPort = 8000
// Job Storage Default Url
var G_MongoUrl = "localhost:27017"
// Global MongoDB object
var G_MongoSession *mgo.Session
var G_MongoDB *mgo.Database
// vegeta jobs current running
var G_RunningVegetaJobs = NewConcurrentSet()
// vegeta jobs will stopping
var G_StoppingVegetaJobs = NewConcurrentSet()
// boom jobs current running
var G_RunningBoomJobs = NewConcurrentSet()
// boom jobs will stopping
var G_StoppingBoomJobs = NewConcurrentSet()
// teams for grouping jobs
var G_AlexTeams = []string{"python"}
// Display Html page layout
var G_ShowLayout = true
// Configuration Object
type Config struct {
BindAddr string
MongoUrl string
Teams []string
ShowLayout bool
}
// Load Config from external json file
func LoadConfig() {
var cfile = flag.String("c", "", "json config file path")
flag.Parse()
if *cfile != "" {
file, err := os.Open(*cfile)
if err != nil {
log.Panic("open config file fail")
}
decoder := json.NewDecoder(file)
config := Config{}
err = decoder.Decode(&config)
if err != nil {
log.Panic("config file not valid json")
}
pairs := strings.Split(config.BindAddr, ":")
G_AlexHost = pairs[0]
G_AlexPort, err = strconv.Atoi(pairs[1])
if err != nil {
log.Panic("port must be int")
}
G_AlexTeams = config.Teams
G_MongoUrl = config.MongoUrl
G_ShowLayout = config.ShowLayout
}
}
func InitGlobals() {
session, err := mgo.Dial(G_MongoUrl)
if err != nil {
log.Panic(err)
}
session.SetMode(mgo.Monotonic, true)
G_MongoSession = session
G_MongoDB = session.DB("alex")
// set golang threads num
runtime.GOMAXPROCS(runtime.NumCPU())
}