-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
49 lines (45 loc) · 1.09 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
package main
import (
"encoding/json"
"io"
"log"
"os"
"strconv"
)
type Configuration struct {
Job map[string]string `json:"job"`
Cookie string `json:"cookie"`
RefreshToken string `json:"refresh_token"`
BuvID string `json:"buv_id"`
Proxy string `json:proxy`
}
func convertJobKeyType(job map[string]string) map[int]string {
result := make(map[int]string)
for key, value := range job {
newKey, err := strconv.Atoi(key)
if err != nil {
log.Fatalf("无法转换键: %v", err)
}
result[newKey] = value
}
return result
}
// Load config from file
func LoadConfig(configFile string) (*Configuration, error) {
config := &Configuration{}
file, err := os.Open(configFile)
if err != nil {
log.Fatalf("无法打开文件: %v", err)
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
log.Fatalf("无法关闭文件: %v", err)
}
}(file)
bytes, err := io.ReadAll(file)
if err := json.Unmarshal(bytes, &config); err != nil {
log.Fatalf("无法解析 JSON 数据: %v", err)
}
return config, err
}