/
dns_config.go
63 lines (55 loc) · 1.51 KB
/
dns_config.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
package domain
import (
"database/sql/driver"
"encoding/json"
"fmt"
"gorm.io/gorm"
"gorm.io/gorm/schema"
"reflect"
)
type DNSConfig struct {
HttpsCertsEnabled bool `json:"http_certs"`
MagicDNS bool `json:"magic_dns"`
OverrideLocalDNS bool `json:"override_local_dns"`
Nameservers []string `json:"nameservers"`
Routes map[string][]string `json:"routes"`
SearchDomains []string `json:"search_domains"`
}
func (i *DNSConfig) Equal(x *DNSConfig) bool {
if i == nil && x == nil {
return true
}
if (i == nil) != (x == nil) {
return false
}
return i.MagicDNS == x.MagicDNS &&
i.HttpsCertsEnabled == x.HttpsCertsEnabled &&
i.OverrideLocalDNS == x.OverrideLocalDNS &&
reflect.DeepEqual(i.Nameservers, x.Nameservers) &&
reflect.DeepEqual(i.Routes, x.Routes) &&
reflect.DeepEqual(i.SearchDomains, x.SearchDomains)
}
func (i *DNSConfig) Scan(destination interface{}) error {
switch value := destination.(type) {
case []byte:
return json.Unmarshal(value, i)
default:
return fmt.Errorf("unexpected data type %T", destination)
}
}
func (i DNSConfig) Value() (driver.Value, error) {
bytes, err := json.Marshal(i)
return bytes, err
}
// GormDataType gorm common data type
func (DNSConfig) GormDataType() string {
return "json"
}
// GormDBDataType gorm db data type
func (DNSConfig) GormDBDataType(db *gorm.DB, field *schema.Field) string {
switch db.Dialector.Name() {
case "sqlite":
return "JSON"
}
return ""
}