From 12512a60dae0ecf4a70712076b1bf1ddc8a329a7 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 7 Mar 2023 10:41:14 +0700 Subject: [PATCH] Always use first record from DNS response --- config.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/config.go b/config.go index 73f648c..45563fe 100644 --- a/config.go +++ b/config.go @@ -205,15 +205,19 @@ func (uc *UpstreamConfig) SetupBootstrapIP() error { if len(r.Answer) == 0 { return errors.New("no answer from bootstrap DNS server") } - for _, a := range r.Answer { - switch ar := a.(type) { + + bootstrapIP := func(record dns.RR) string { + switch ar := record.(type) { case *dns.A: - uc.BootstrapIP = ar.A.String() - //lint:ignore S1023 false alarm? - break + return ar.A.String() case *dns.AAAA: - uc.BootstrapIP = ar.AAAA.String() - //lint:ignore S1023 false alarm? + return ar.AAAA.String() + } + return "" + } + for _, a := range r.Answer { + if ip := bootstrapIP(a); ip != "" { + uc.BootstrapIP = ip break } }