ソースを参照

Minor cleanups

Ask Bjørn Hansen 7 年 前
コミット
32eef93089
2 ファイル変更10 行追加6 行削除
  1. 5 5
      zones/muxmanager.go
  2. 5 1
      zones/picker.go

+ 5 - 5
zones/muxmanager.go

@@ -194,11 +194,11 @@ func (mm *MuxManager) setupRootZone() {
 }
 
 func sha256File(fn string) string {
-	if data, err := ioutil.ReadFile(fn); err != nil {
+	data, err := ioutil.ReadFile(fn)
+	if err != nil {
 		return ""
-	} else {
-		hasher := sha256.New()
-		hasher.Write(data)
-		return hex.EncodeToString(hasher.Sum(nil))
 	}
+	hasher := sha256.New()
+	hasher.Write(data)
+	return hex.EncodeToString(hasher.Sum(nil))
 }

+ 5 - 1
zones/picker.go

@@ -23,6 +23,10 @@ func (zone *Zone) filterHealth(servers Records) (Records, int) {
 	return tmpServers, sum
 }
 
+// Picker picks the best results from a label matching the qtype,
+// up to 'max' results. If location is specified Picker will get
+// return the "closests" results, otherwise they are returned weighted
+// randomized.
 func (zone *Zone) Picker(label *Label, qtype uint16, max int, location *geo.Location) Records {
 
 	if qtype == dns.TypeANY {
@@ -104,7 +108,7 @@ func (zone *Zone) Picker(label *Label, qtype uint16, max int, location *geo.Loca
 		for chosen < max {
 			// Determine the minimum distance of servers not yet chosen
 			minDist := location.MaxDistance()
-			for i, _ := range servers {
+			for i := range servers {
 				if !choose[i] && distances[i] <= minDist {
 					minDist = distances[i]
 				}