cmd/cli: use resolvconffile lib for parsing

This commit is contained in:
Cuong Manh Le
2025-06-17 19:33:45 +07:00
committed by Cuong Manh Le
parent b9b9cfcade
commit 64632fa640
3 changed files with 57 additions and 26 deletions
+8 -5
View File
@@ -1,5 +1,3 @@
//go:build !js && !windows
package resolvconffile
import (
@@ -24,15 +22,20 @@ func NameServersWithPort() []string {
}
func NameServers() []string {
c, err := resolvconffile.ParseFile(resolvconfPath)
nss, _ := NameserversFromFile(resolvconfPath)
return nss
}
func NameserversFromFile(path string) ([]string, error) {
c, err := resolvconffile.ParseFile(path)
if err != nil {
return nil
return nil, err
}
ns := make([]string, 0, len(c.Nameservers))
for _, nameserver := range c.Nameservers {
ns = append(ns, nameserver.String())
}
return ns
return ns, nil
}
// SearchDomains returns the current search domains config in /etc/resolv.conf file.