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:
Cuong Manh Le
2025-06-18 15:50:30 +07:00
committed by Cuong Manh Le
parent 64632fa640
commit f0cb810dd6
8 changed files with 25 additions and 17 deletions
+7
View File
@@ -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 {