initBootstrap initializes the [upstream.Resolver] for bootstrapping upstream servers. It returns the default resolver if no bootstraps were specified. The returned resolver will also use system hosts files first.
( ctx context.Context, l *slog.Logger, bootstraps []string, opts *upstream.Options, )
| 246 | // servers. It returns the default resolver if no bootstraps were specified. |
| 247 | // The returned resolver will also use system hosts files first. |
| 248 | func initBootstrap( |
| 249 | ctx context.Context, |
| 250 | l *slog.Logger, |
| 251 | bootstraps []string, |
| 252 | opts *upstream.Options, |
| 253 | ) (r upstream.Resolver, err error) { |
| 254 | var resolvers []upstream.Resolver |
| 255 | |
| 256 | for i, b := range bootstraps { |
| 257 | var ur *upstream.UpstreamResolver |
| 258 | ur, err = upstream.NewUpstreamResolver(b, opts) |
| 259 | if err != nil { |
| 260 | return nil, fmt.Errorf("creating bootstrap resolver at index %d: %w", i, err) |
| 261 | } |
| 262 | |
| 263 | resolvers = append(resolvers, upstream.NewCachingResolver(ur)) |
| 264 | } |
| 265 | |
| 266 | switch len(resolvers) { |
| 267 | case 0: |
| 268 | etcHosts, hostsErr := upstream.NewDefaultHostsResolver(ctx, osutil.RootDirFS(), l) |
| 269 | if hostsErr != nil { |
| 270 | l.ErrorContext(ctx, "creating default hosts resolver", slogutil.KeyError, hostsErr) |
| 271 | |
| 272 | return net.DefaultResolver, nil |
| 273 | } |
| 274 | |
| 275 | return upstream.ConsequentResolver{etcHosts, net.DefaultResolver}, nil |
| 276 | case 1: |
| 277 | return resolvers[0], nil |
| 278 | default: |
| 279 | return upstream.ParallelResolver(resolvers), nil |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | // initEDNS inits EDNS-related config fields. |
| 284 | func (conf *configuration) initEDNS( |
no test coverage detected
searching dependent graphs…