-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
57 lines (50 loc) · 899 Bytes
/
main.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
package main
import (
"clash-cli/api"
"clash-cli/model"
"clash-cli/step"
"clash-cli/storage"
"log"
)
func main() {
checkConf()
root := step.Root{
Client: getClientData(),
}
if err := root.Run(); err != nil {
log.Fatalln(err)
}
}
func checkConf() {
db, err := storage.Open()
if err != nil {
log.Fatalln(err)
}
defer db.Close()
if err = db.CheckKey(model.DB_KEY_URL, model.DEFAULT_API_URL); err != nil {
log.Fatalln(err)
}
if err = db.CheckKey(model.DB_KEY_SECRET, model.DEFAULT_API_SECRET); err != nil {
log.Fatalln(err)
}
}
func getClientData() *api.Client {
db, err := storage.Open()
if err != nil {
log.Fatalln(err)
}
defer db.Close()
baseUrl, err := db.GetUrl()
if err != nil {
log.Fatalln(err)
}
secret, err := db.GetSecret()
if err != nil {
log.Fatalln(err)
}
client := &api.Client{
BaseURL: baseUrl,
Secret: secret,
}
return client
}