Repository navigation
Expand file tree
/
Copy pathconfig.go
More file actions
59 lines (51 loc) · 1.63 KB
/
Copy pathconfig.go
File metadata and controls
59 lines (51 loc) · 1.63 KB
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
package main
import (
"log"
"github.com/Unknwon/goconfig"
)
type Config struct {
TestDataPath string
TempPath string
RunPath string
RMQHost string
RMQPort int
RMQUser string
RMQPassword string
RMQQueueName string
SQLHost string
SQLPort int
SQLUser string
SQLPassword string
SQLDatabase string
RedisHost string
RedisPort int
}
func ParseConfig(path string) (config *Config, err error) {
c, err := goconfig.LoadConfigFile(path)
config = &Config{}
config.TestDataPath = c.MustValue("default", "testdata", "./testdata/")
config.TempPath = c.MustValue("default", "tmp", "./tmp/")
config.RunPath = c.MustValue("default", "runpath", "./rundir/")
config.RMQHost = c.MustValue("rabbitmq", "host", "localhost")
config.RMQPort = c.MustInt("rabbitmq", "port", 5672)
config.RMQUser = c.MustValue("rabbitmq", "user", "guest")
config.RMQPassword = c.MustValue("rabbitmq", "password", "guest")
config.RMQQueueName = c.MustValue("rabbitmq", "queue", "judge_task")
config.SQLHost = c.MustValue("mysql", "host", "localhost")
config.SQLPort = c.MustInt("mysql", "port", 3306)
config.SQLUser = c.MustValue("mysql", "user")
if config.SQLUser == "" {
log.Fatalln("Config Error: No mysql user")
}
config.SQLPassword = c.MustValue("mysql", "password")
if config.SQLPassword == "" {
log.Fatalln("Config Error: No mysql password")
}
config.SQLDatabase = c.MustValue("mysql", "database")
if config.SQLDatabase == "" {
log.Fatalln("Config Error: No mysql database")
}
config.RedisHost = c.MustValue("redis", "host", "localhost")
config.RedisPort = c.MustInt("redis", "posr", 6379)
return
}