mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
Make nameserver resolution functions more consistent and accessible: - Rename currentNameserversFromResolvconf to CurrentNameserversFromResolvconf - Move function to public API for better reusability - Update all internal references to use the new public API - Add comprehensive godoc comments for nameserver functions - Improve code organization by centralizing DNS resolution logic This change makes the nameserver resolution functionality more maintainable and easier to use across different parts of the codebase.
40 lines
761 B
Go
40 lines
761 B
Go
package ctrld
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Control-D-Inc/ctrld/internal/resolvconffile"
|
|
)
|
|
|
|
type dnsFn func(ctx context.Context) []string
|
|
|
|
// nameservers returns DNS nameservers from system settings.
|
|
func nameservers(ctx context.Context) []string {
|
|
var dns []string
|
|
seen := make(map[string]bool)
|
|
ch := make(chan []string)
|
|
fns := dnsFns()
|
|
|
|
for _, fn := range fns {
|
|
go func(fn dnsFn) {
|
|
ch <- fn(ctx)
|
|
}(fn)
|
|
}
|
|
for range fns {
|
|
for _, ns := range <-ch {
|
|
if seen[ns] {
|
|
continue
|
|
}
|
|
seen[ns] = true
|
|
dns = append(dns, ns)
|
|
}
|
|
}
|
|
|
|
return dns
|
|
}
|
|
|
|
// CurrentNameserversFromResolvconf returns the current nameservers set from /etc/resolv.conf file.
|
|
func CurrentNameserversFromResolvconf() []string {
|
|
return resolvconffile.NameServers()
|
|
}
|