Ver Fonte

libnetwork/resolvconf: fix some minor (linting) issues

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn há 2 anos atrás
pai
commit
56fbbde2ed
1 ficheiros alterados com 10 adições e 9 exclusões
  1. 10 9
      libnetwork/resolvconf/resolvconf.go

+ 10 - 9
libnetwork/resolvconf/resolvconf.go

@@ -148,7 +148,7 @@ func getLines(input []byte, commentMarker []byte) [][]byte {
 
 // GetNameservers returns nameservers (if any) listed in /etc/resolv.conf
 func GetNameservers(resolvConf []byte, kind int) []string {
-	nameservers := []string{}
+	var nameservers []string
 	for _, line := range getLines(resolvConf, []byte("#")) {
 		var ns [][]byte
 		if kind == IP {
@@ -169,7 +169,7 @@ func GetNameservers(resolvConf []byte, kind int) []string {
 // /etc/resolv.conf as CIDR blocks (e.g., "1.2.3.4/32")
 // This function's output is intended for net.ParseCIDR
 func GetNameserversAsCIDR(resolvConf []byte) []string {
-	nameservers := []string{}
+	var nameservers []string
 	for _, nameserver := range GetNameservers(resolvConf, IP) {
 		var address string
 		// If IPv6, strip zone if present
@@ -187,7 +187,7 @@ func GetNameserversAsCIDR(resolvConf []byte) []string {
 // If more than one search line is encountered, only the contents of the last
 // one is returned.
 func GetSearchDomains(resolvConf []byte) []string {
-	domains := []string{}
+	var domains []string
 	for _, line := range getLines(resolvConf, []byte("#")) {
 		match := searchRegexp.FindSubmatch(line)
 		if match == nil {
@@ -202,7 +202,7 @@ func GetSearchDomains(resolvConf []byte) []string {
 // If more than one options line is encountered, only the contents of the last
 // one is returned.
 func GetOptions(resolvConf []byte) []string {
-	options := []string{}
+	var options []string
 	for _, line := range getLines(resolvConf, []byte("#")) {
 		match := optionsRegexp.FindSubmatch(line)
 		if match == nil {
@@ -213,10 +213,11 @@ func GetOptions(resolvConf []byte) []string {
 	return options
 }
 
-// Build writes a configuration file to path containing a "nameserver" entry
-// for every element in dns, a "search" entry for every element in
-// dnsSearch, and an "options" entry for every element in dnsOptions.
-func Build(path string, dns, dnsSearch, dnsOptions []string) (*File, error) {
+// Build generates and writes a configuration file to path containing a nameserver
+// entry for every element in nameservers, a "search" entry for every element in
+// dnsSearch, and an "options" entry for every element in dnsOptions. It returns
+// a File containing the generated content and its (sha256) hash.
+func Build(path string, nameservers, dnsSearch, dnsOptions []string) (*File, error) {
 	content := bytes.NewBuffer(nil)
 	if len(dnsSearch) > 0 {
 		if searchString := strings.Join(dnsSearch, " "); strings.Trim(searchString, " ") != "." {
@@ -225,7 +226,7 @@ func Build(path string, dns, dnsSearch, dnsOptions []string) (*File, error) {
 			}
 		}
 	}
-	for _, dns := range dns {
+	for _, dns := range nameservers {
 		if _, err := content.WriteString("nameserver " + dns + "\n"); err != nil {
 			return nil, err
 		}