Skip to content

Commit 0a3ef69

Browse files
gofmt
1 parent 87fe0d4 commit 0a3ef69

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

cmd/root.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ var (
3232

3333
// EnsureDNSAddress formats the DNS server address properly.
3434
func EnsureDNSAddress(server string) string {
35-
if strings.Contains(server, "]") || strings.Contains(server, ":") && net.ParseIP(server) == nil {
36-
return server
37-
}
38-
39-
ip := net.ParseIP(server)
40-
if ip != nil && ip.To4() == nil { // It's IPv6 (and not IPv4)
41-
return "[" + server + "]:53"
42-
}
43-
// Otherwise, assume IPv4 or hostname, so append port normally.
44-
return server + ":53"
35+
if strings.Contains(server, "]") || strings.Contains(server, ":") && net.ParseIP(server) == nil {
36+
return server
37+
}
38+
39+
ip := net.ParseIP(server)
40+
if ip != nil && ip.To4() == nil { // It's IPv6 (and not IPv4)
41+
return "[" + server + "]:53"
42+
}
43+
// Otherwise, assume IPv4 or hostname, so append port normally.
44+
return server + ":53"
4545
}
4646

4747
func NewRootCommand() *cobra.Command {

cmd/root_test.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,20 @@ func Test_Cmd_LogFile_Debug(t *testing.T) {
189189
}
190190

191191
func TestEnsureDNSAddress(t *testing.T) {
192-
testCases := []struct {
193-
input string
194-
expected string
195-
}{
196-
{"127.0.0.1", "127.0.0.1:53"},
197-
{"2001:558:feed::1", "[2001:558:feed::1]:53"},
198-
{"[2001:558:feed::1]:53", "[2001:558:feed::1]:53"},
199-
{"example.com", "example.com:53"},
200-
}
201-
202-
for _, tc := range testCases {
203-
t.Run(fmt.Sprintf("input=%s", tc.input), func(t *testing.T) {
204-
result := EnsureDNSAddress(tc.input)
205-
assert.Equal(t, tc.expected, result)
206-
})
207-
}
192+
testCases := []struct {
193+
input string
194+
expected string
195+
}{
196+
{"127.0.0.1", "127.0.0.1:53"},
197+
{"2001:558:feed::1", "[2001:558:feed::1]:53"},
198+
{"[2001:558:feed::1]:53", "[2001:558:feed::1]:53"},
199+
{"example.com", "example.com:53"},
200+
}
201+
202+
for _, tc := range testCases {
203+
t.Run(fmt.Sprintf("input=%s", tc.input), func(t *testing.T) {
204+
result := EnsureDNSAddress(tc.input)
205+
assert.Equal(t, tc.expected, result)
206+
})
207+
}
208208
}

0 commit comments

Comments
 (0)