-
Notifications
You must be signed in to change notification settings - Fork 4
/
domain.go
64 lines (52 loc) · 1.29 KB
/
domain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
)
type Domain struct {
Name string `json:"name"`
Qtype string `json:"type"`
Ns string `json:"ns"`
Interval int `json:"interval"`
}
type Domains []Domain
func (obj *Domain) Complete(Qtype string, Interval int, Ns string) {
if obj.Qtype == "" {
obj.Qtype = Qtype
}
if obj.Interval == 0 {
obj.Interval = Interval
}
if obj.Ns == "" {
obj.Ns = Ns
}
}
//check Control domain properties
func (obj *Domain) Check() []string {
var errors []string
if !IsDomain(obj.Name) {
errors = append(errors, "Domain is not valid: "+obj.Name)
}
if !(obj.Qtype == "ip" || obj.Qtype == "ip6") {
errors = append(errors, "Type is not IP or ip6: "+obj.Qtype)
}
if obj.Interval < 100 {
errors = append(errors, "Interval is too low: "+fmt.Sprint(obj.Interval))
}
if !(IsIPv4(obj.Ns) || IsIPv6(obj.Ns)) {
errors = append(errors, "Name server is not valid IP address: "+obj.Ns)
}
return errors
}
//String Domain to string
func (k Domain) String() string {
return fmt.Sprintf("%s type:%s ns:%s interval:%v", k.Name, k.Qtype, k.Ns, k.Interval)
}
func (k Domains) Check() [][]string {
var stat [][]string
for i := range k {
if control := k[i].Check(); control != nil {
stat = append(stat, append([]string{k[i].Name}, control...))
}
}
return stat
}