forked from rancher/rancher-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
83 lines (71 loc) · 2.55 KB
/
Copy pathtypes.go
File metadata and controls
83 lines (71 loc) · 2.55 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"encoding/json"
yaml "gopkg.in/yaml.v3"
)
type RecordA struct {
Ttl *uint32 `json:"-" yaml:"ttl,omitempty"`
Answer []string `json:"answer" yaml:"answer"`
}
type RecordCname struct {
Ttl *uint32 `json:"-" yaml:"ttl,omitempty"`
Answer string `json:"answer" yaml:"answer"`
}
type RecordPtr struct {
Ttl *uint32 `json:"-" yaml:"ttl,omitempty"`
Answer string `json:"answer" yaml:"answer"`
}
type RecordTxt struct {
Ttl *uint32 `json:"-" yaml:"ttl,omitempty"`
Answer []string `json:"answer" yaml:"answer"`
}
type ClientAnswers struct {
Search []string `json:"search" yaml:"search"`
Recurse []string `json:"recurse" yaml:"recurse"`
Authoritative []string `json:"authoritative" yaml:"authoritative"`
A map[string]RecordA `json:"a" yaml:"a"`
Cname map[string]RecordCname `json:"cname" yaml:"cname"`
Ptr map[string]RecordPtr `json:"ptr,omitempty" yaml:"ptr,omitempty"`
Txt map[string]RecordTxt `json:"txt,omitempty" yaml:"txt,omitempty"`
}
type clientAnswersWire struct {
Search []string `json:"search" yaml:"search"`
Recurse []string `json:"recurse" yaml:"recurse"`
Authoritative *[]string `json:"authoritative" yaml:"authoritative"`
LegacyAuthoritative *[]string `json:"authorative" yaml:"authorative"`
A map[string]RecordA `json:"a" yaml:"a"`
Cname map[string]RecordCname `json:"cname" yaml:"cname"`
Ptr map[string]RecordPtr `json:"ptr,omitempty" yaml:"ptr,omitempty"`
Txt map[string]RecordTxt `json:"txt,omitempty" yaml:"txt,omitempty"`
}
func (wire clientAnswersWire) apply(target *ClientAnswers) {
target.Search = wire.Search
target.Recurse = wire.Recurse
target.A = wire.A
target.Cname = wire.Cname
target.Ptr = wire.Ptr
target.Txt = wire.Txt
target.Authoritative = nil
if wire.Authoritative != nil {
target.Authoritative = *wire.Authoritative
} else if wire.LegacyAuthoritative != nil {
target.Authoritative = *wire.LegacyAuthoritative
}
}
func (answers *ClientAnswers) UnmarshalJSON(data []byte) error {
var wire clientAnswersWire
if err := json.Unmarshal(data, &wire); err != nil {
return err
}
wire.apply(answers)
return nil
}
func (answers *ClientAnswers) UnmarshalYAML(value *yaml.Node) error {
var wire clientAnswersWire
if err := value.Decode(&wire); err != nil {
return err
}
wire.apply(answers)
return nil
}
type Answers map[string]ClientAnswers