-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.go
53 lines (47 loc) · 1.11 KB
/
config.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
package main
import (
"log"
"net/url"
"os"
"path/filepath"
"time"
"github.com/jinzhu/configor"
"gopkg.in/yaml.v2"
)
func LoadConfig() {
pwd, _ := os.Getwd()
ConfigPath := filepath.Join(pwd, "conf", "config.yml")
os.MkdirAll("./conf", 0755)
// 检查配置文件是否存在
_, err1 := os.Stat(ConfigPath)
if os.IsNotExist(err1) {
data, _ := yaml.Marshal(Config{
ProxyUrl: "",
ExpTime: 25,
IntervalTime: 3,
Auth: Auth{
UserName: "",
Password: "",
},
DetailLog: false,
})
os.Create(ConfigPath)
os.WriteFile(ConfigPath, data, 0644)
log.Println("Frist Run, Init config.yml...")
} else if err1 == nil {
log.Println("Load config.yml")
} else {
log.Println("Load Config Error:", err1)
}
configor.Load(&config, "conf/config.yml")
url, err2 := url.Parse(config.ProxyUrl)
if config.ProxyUrl == "" {
log.Println("Please Fill ProxyUrl to Config:")
time.Sleep(3 * time.Second)
os.Exit(-1)
} else if err2 != nil {
log.Println("Failed to parse proxy URL:", url)
time.Sleep(3 * time.Second)
os.Exit(-1)
}
}