-
Notifications
You must be signed in to change notification settings - Fork 2
/
contact_json_gen.go
109 lines (95 loc) · 2.29 KB
/
contact_json_gen.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package openapi
// This file was automatically generated.
// DO NOT EDIT MANUALLY. All changes will be lost
import (
"encoding/json"
"log"
"strings"
"github.com/pkg/errors"
)
var _ = log.Printf
var _ = json.Unmarshal
var _ = errors.Cause
type contactMarshalProxy struct {
Reference string `json:"$ref,omitempty"`
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Email string `json:"email,omitempty"`
}
type contactUnmarshalProxy struct {
Reference string `json:"$ref,omitempty"`
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Email string `json:"email,omitempty"`
}
func (v *contact) MarshalJSON() ([]byte, error) {
var proxy contactMarshalProxy
if len(v.reference) > 0 {
proxy.Reference = v.reference
return json.Marshal(proxy)
}
proxy.Name = v.name
proxy.URL = v.url
proxy.Email = v.email
return json.Marshal(proxy)
}
func (v *contact) UnmarshalJSON(data []byte) error {
var proxy contactUnmarshalProxy
if err := json.Unmarshal(data, &proxy); err != nil {
return errors.Wrapf(err, `failed to unmarshal contact`)
}
if len(proxy.Reference) > 0 {
v.reference = proxy.Reference
return nil
}
v.name = proxy.Name
v.url = proxy.URL
v.email = proxy.Email
return nil
}
func (v *contact) QueryJSON(path string) (ret interface{}, ok bool) {
path = strings.TrimLeftFunc(path, func(r rune) bool { return r == '#' || r == '/' })
if path == "" {
return v, true
}
var frag string
if i := strings.Index(path, "/"); i > -1 {
frag = path[:i]
path = path[i+1:]
} else {
frag = path
path = ""
}
var target interface{}
switch frag {
case "name":
target = v.name
case "url":
target = v.url
case "email":
target = v.email
default:
return nil, false
}
if qj, ok := target.(QueryJSONer); ok {
return qj.QueryJSON(path)
}
if path == "" {
return target, true
}
return nil, false
}
// ContactFromJSON constructs a Contact from JSON buffer. `dst` must
// be a pointer to `Contact`
func ContactFromJSON(buf []byte, dst interface{}) error {
v, ok := dst.(*Contact)
if !ok {
return errors.Errorf(`dst needs to be a pointer to Contact, but got %T`, dst)
}
var tmp contact
if err := json.Unmarshal(buf, &tmp); err != nil {
return errors.Wrap(err, `failed to unmarshal Contact`)
}
*v = &tmp
return nil
}