-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
65 lines (55 loc) · 1.08 KB
/
config.go
File metadata and controls
65 lines (55 loc) · 1.08 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
60
61
62
63
64
65
package main
import (
"encoding/json"
"os"
"strings"
"time"
)
type config struct {
Website string `json:"website"`
Proxy string `json:"proxy"`
Threads int `json:"threads"`
Headers struct {
UserAgent string `json:"user_agent"`
Accept string `json:"accept"`
} `json:"headers"`
Print struct {
Enabled bool `json:"enabled"`
GeoInfo bool `json:"geo_info"`
} `json:"print"`
Timeout struct {
HTTP int `json:"http"`
Socks4 int `json:"socks4"`
Socks5 int `json:"socks5"`
} `json:"timeout"`
}
func (c *config) getTimeout() time.Duration {
var sec int
switch c.Proxy {
case "socks4":
sec = c.Timeout.Socks4
case "socks5":
sec = c.Timeout.Socks5
default:
sec = c.Timeout.HTTP
}
if sec < 1 {
sec = 10
}
return time.Duration(sec) * time.Second
}
func loadConfig(path string) (*config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
cfg := &config{}
if err := json.Unmarshal(data, cfg); err != nil {
return nil, err
}
cfg.Proxy = strings.ToLower(cfg.Proxy)
if cfg.Threads < 1 {
cfg.Threads = 1000
}
return cfg, nil
}