diff options
| author | Shulhan <ms@kilabit.info> | 2019-02-07 13:54:47 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-02-07 13:54:47 +0700 |
| commit | a52f3e613c490366f1c867ca297ba46be0ea81c3 (patch) | |
| tree | f28f3f3a65ca915603b8bf2c58655890128c0c6d /lib/dns/funcs.go | |
| parent | c05eade29b6f506115870bc50a548bb9d0ac3e71 (diff) | |
| download | pakakeh.go-a52f3e613c490366f1c867ca297ba46be0ea81c3.tar.xz | |
dns: add function to get list of system name servers
Diffstat (limited to 'lib/dns/funcs.go')
| -rw-r--r-- | lib/dns/funcs.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/dns/funcs.go b/lib/dns/funcs.go new file mode 100644 index 00000000..e2ab2468 --- /dev/null +++ b/lib/dns/funcs.go @@ -0,0 +1,26 @@ +// Copyright 2019, Shulhan <ms@kilabit.info>. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package dns + +import ( + libnet "github.com/shuLhan/share/lib/net" +) + +// +// GetSystemNameServers return list of system name servers by reading +// resolv.conf formatted file in path. +// +// Default path is "/etc/resolv.conf". +// +func GetSystemNameServers(path string) []string { + if len(path) == 0 { + path = "/etc/resolv.conf" + } + rc, err := libnet.NewResolvConf(path) + if err != nil { + return nil + } + return rc.NameServers +} |
