-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathtypes.go
68 lines (56 loc) · 1.51 KB
/
types.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
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"net"
"strconv"
"strings"
clsconst "github.com/Dreamacro/clash/constant"
"github.com/spf13/viper"
)
type Conf struct {
Debug bool
DNSHost string
DNSPort string
TProxyPort string
FakeIPRange string
ExternalUI string
}
func parseConf() (*Conf, error) {
debug := viper.GetString("log-level")
enhancedMode := viper.GetString("dns.enhanced-mode")
tproxyPort := viper.GetInt("tproxy-port")
dnsListen := viper.GetString("dns.listen")
fakeIPRange := viper.GetString("dns.fake-ip-range")
externalUI := viper.GetString("external-ui")
if strings.ToLower(enhancedMode) != clsconst.DNSFakeIP.String() {
return nil, fmt.Errorf("only support fake-ip dns mode")
}
if tproxyPort < 1 {
return nil, fmt.Errorf("tproxy port in clash config is missing(tproxy-port)")
}
dnsHost, dnsPort, err := net.SplitHostPort(dnsListen)
if err != nil {
return nil, fmt.Errorf("failed to parse clash dns listen config: %v", err)
}
dport, err := strconv.Atoi(dnsPort)
if err != nil {
return nil, fmt.Errorf("failed to parse clash dns listen config: %v", err)
}
if dport < 1 {
return nil, fmt.Errorf("dns port in clash config is missing(dns.listen)")
}
if fakeIPRange == "" {
fakeIPRange = "198.18.0.1/16"
}
if externalUI == "" {
externalUI = "dashboard"
}
return &Conf{
Debug: strings.ToLower(debug) == "debug",
DNSHost: dnsHost,
DNSPort: dnsPort,
TProxyPort: strconv.Itoa(tproxyPort),
FakeIPRange: fakeIPRange,
ExternalUI: externalUI,
}, nil
}