-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.go
More file actions
76 lines (64 loc) · 1.81 KB
/
env.go
File metadata and controls
76 lines (64 loc) · 1.81 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
package main
import (
"fmt"
"os"
"github.com/sirupsen/logrus"
)
type Settings struct {
UdpPort string
UdpAddress string
TcpPort string
TcpAddress string
DnsUpstreamPort string
DnsUpstreamAddress string
LogLevel logrus.Level
}
func (s Settings) String() string {
return fmt.Sprintf("UdpPort: %s, UdpAddress: %s, TcpPort: %s, TcpAddress: %s, DnsUpstreamPort: %s, DnsUpstreamAddress: %s, LogLevel: %s",
s.UdpPort,
s.UdpAddress,
s.TcpPort,
s.TcpAddress,
s.DnsUpstreamPort,
s.DnsUpstreamAddress,
s.LogLevel,
)
}
func getSettingsFromEnvVars() *Settings {
var udpport, udpaddress, tcpport, tcpaddress, dnsupstreamport, dnsupstreamaddress, loglevelstring string
if udpport = os.Getenv("UDP_PORT"); udpport == "" {
udpport = "53"
}
if udpaddress = os.Getenv("UDP_ADDRESS"); udpaddress == "" {
udpaddress = "0.0.0.0"
}
if tcpport = os.Getenv("TCP_PORT"); tcpport == "" {
tcpport = "53"
}
if tcpaddress = os.Getenv("TCP_ADDRESS"); tcpaddress == "" {
tcpaddress = "0.0.0.0"
}
if dnsupstreamport = os.Getenv("DNS_UPSTREAM_PORT"); dnsupstreamport == "" {
dnsupstreamport = "853"
}
if dnsupstreamaddress = os.Getenv("DNS_UPSTREAM_ADDRESS"); dnsupstreamaddress == "" {
dnsupstreamaddress = "1.1.1.1"
}
if loglevelstring = os.Getenv("LOG_LEVEL"); loglevelstring == "" {
loglevelstring = "error"
}
loglevel, err := logrus.ParseLevel(loglevelstring)
if err != nil {
logrus.Error(fmt.Sprintf("%s is not a valid LogLevel, Using default", loglevelstring))
loglevel = logrus.ErrorLevel
}
return &Settings{
UdpPort: udpport,
UdpAddress: udpaddress,
TcpPort: tcpport,
TcpAddress: tcpaddress,
DnsUpstreamPort: dnsupstreamport,
DnsUpstreamAddress: dnsupstreamaddress,
LogLevel: loglevel,
}
}