mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-05-15 00:50:25 +02:00
all: move nameserver resolution to public API
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.
This commit is contained in:
committed by
Cuong Manh Le
parent
64632fa640
commit
f0cb810dd6
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
const resolvconfPath = "/etc/resolv.conf"
|
||||
|
||||
// NameServersWithPort retrieves a list of nameservers with the default DNS port 53 appended to each address.
|
||||
func NameServersWithPort() []string {
|
||||
c, err := resolvconffile.ParseFile(resolvconfPath)
|
||||
if err != nil {
|
||||
@@ -21,11 +22,17 @@ func NameServersWithPort() []string {
|
||||
return ns
|
||||
}
|
||||
|
||||
// NameServers retrieves a list of nameservers from the /etc/resolv.conf file
|
||||
// Returns an empty slice if reading fails.
|
||||
func NameServers() []string {
|
||||
nss, _ := NameserversFromFile(resolvconfPath)
|
||||
return nss
|
||||
}
|
||||
|
||||
// NameserversFromFile reads nameserver addresses from the specified resolv.conf file
|
||||
// and returns them as a slice of strings.
|
||||
//
|
||||
// Returns an error if the file cannot be parsed.
|
||||
func NameserversFromFile(path string) ([]string, error) {
|
||||
c, err := resolvconffile.ParseFile(path)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user