forked from usam123/eproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
81 lines (67 loc) · 1.7 KB
/
init.go
File metadata and controls
81 lines (67 loc) · 1.7 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"encoding/json"
"os"
"strings"
"github.com/Unknwon/goconfig"
)
type Config struct {
Str string `json:"Str"`
Replace string `json:"Replace"`
IsComplete bool `json:"IsComplete"`
}
func Init() ([]Config, string, string, error) {
filename := "conf.ini"
exist, err := PathExists(filename)
if err != nil {
//fmt.Printf("get dir error![%v]\n", err)
return nil, "", "", err
}
if !exist {
fc, err := os.Create(filename)
if err != nil {
return nil, "", "", err
} else {
_, err = fc.Write([]byte("[json]\ndata =\ntargetUrl =\nproxyUrl =\nsocks5 ="))
}
fc.Close()
}
cfg, err := goconfig.LoadConfigFile(filename)
if err != nil {
// panic("错误")
return nil, "", "", err
}
conf_json, err := cfg.GetValue("json", "data")
target_url, err := cfg.GetValue("json", "targetUrl")
proxyUrl, err := cfg.GetValue("json", "proxyUrl")
socks5, err := cfg.GetValue("json", "socks5")
if len(target_url) == 0 {
target_url = "https://google.com"
}
var conf []Config
if conf_json != "" {
err = json.Unmarshal([]byte(conf_json), &conf)
if err != nil {
return nil, "", "", err
}
if strings.Contains(target_url, "http") && strings.Contains(proxyUrl, "http") {
target_url_arr := strings.Split(target_url, "://")
proxyUrl_arr := strings.Split(proxyUrl, "://")
conf_tp := Config{
Str: target_url_arr[1],
Replace: proxyUrl_arr[1],
IsComplete: false,
}
conf = append(conf, conf_tp)
if target_url_arr[0] != proxyUrl_arr[0] {
conf_tp = Config{
Str: target_url_arr[0],
Replace: proxyUrl_arr[0],
IsComplete: false,
}
conf = append(conf, conf_tp)
}
}
}
return conf, target_url, socks5, err
}