소스 검색

Support health label for A, AAAA and PTR records

Ask Bjørn Hansen 8 년 전
부모
커밋
91973fc501
1개의 변경된 파일37개의 추가작업 그리고 4개의 파일을 삭제
  1. 37 4
      zones/reader.go

+ 37 - 4
zones/reader.go

@@ -256,10 +256,43 @@ func setupZoneData(data map[string]interface{}, zone *Zone) {
 
 				switch dnsType {
 				case dns.TypeA, dns.TypeAAAA, dns.TypePTR:
-					// todo: check interface type
-					str, weight := getStringWeight(records[rType][i].([]interface{}))
-					ip := str
-					record.Weight = weight
+
+					rec := records[rType][i]
+
+					var ip string
+
+					switch rec.(type) {
+
+					case []interface{}:
+						str, weight := getStringWeight(records[rType][i].([]interface{}))
+						ip = str
+						record.Weight = weight
+
+					case map[string]interface{}:
+						r := rec.(map[string]interface{})
+
+						ip = r["ip"].(string)
+
+						if len(ip) == 0 || dnsType == dns.TypePTR {
+							switch dnsType {
+							case dns.TypeA:
+								ip = r["a"].(string)
+							case dns.TypeAAAA:
+								ip = r["aaaa"].(string)
+							case dns.TypePTR:
+								ip = r["ptr"].(string)
+							}
+						}
+
+						if w, ok := r["weight"]; ok {
+							record.Weight = typeutil.ToInt(w)
+						}
+
+						if h, ok := r["health"]; ok {
+							record.Test = typeutil.ToString(h)
+						}
+
+					}
 
 					switch dnsType {
 					case dns.TypePTR: