-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.go
186 lines (155 loc) · 5.44 KB
/
misc.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Code generated by jsonschema. DO NOT EDIT.
package beerjson
import "encoding/json"
import "fmt"
// ID: https://raw.githubusercontent.com/beerjson/beerjson/master/json/misc.json
// MiscellaneousAdditionType collects the attributes of each miscellaneous ingredient for use in a recipe.
type MiscellaneousAdditionType struct {
MiscellaneousBaseType *MiscellaneousBaseType `json:"type,omitempty"`
// The timing object fully describes the timing of an addition with options for basis on time, gravity, or pH at any process step.
Timing *TimingType `json:"timing,omitempty"`
Amount MiscellaneousAdditionTypeAmount `json:"amount,omitempty", validate:"oneof"`
Name *string `json:"name,omitempty"`
Producer *string `json:"producer,omitempty"`
ProductId *string `json:"product_id,omitempty"`
}
func (s *MiscellaneousAdditionType) UnmarshalJSON(b []byte) error {
m := map[string]json.RawMessage{}
if err := json.Unmarshal(b, &m); err != nil {
return nil
}
miscellaneousAdditionTypeAmount := func() MiscellaneousAdditionTypeAmount {
raw, ok := m["amount"]
if !ok {
return nil
}
var volumeType VolumeType
if err := json.Unmarshal(raw, &volumeType); err == nil {
return &volumeType
}
var massType MassType
if err := json.Unmarshal(raw, &massType); err == nil {
return &massType
}
var unitType UnitType
if err := json.Unmarshal(raw, &unitType); err == nil {
return &unitType
}
return nil
}
type Alias MiscellaneousAdditionType
aux := &struct {
Amount MiscellaneousAdditionTypeAmount `json:"amount,omitempty", validate:"oneof"`
*Alias
}{
Amount: miscellaneousAdditionTypeAmount(),
Alias: (*Alias)(s),
}
if err := json.Unmarshal(b, &aux); err != nil {
return err
}
s.Amount = aux.Amount
return nil
}
// MiscellaneousAdditionTypeAmount
type MiscellaneousAdditionTypeAmount interface {
MiscellaneousAdditionTypeamount()
}
// MiscellaneousBase provides unique properties to identify individual records of ingredients that are neither hops, nor provide a contribution to the gravity of wort.
type MiscellaneousBase struct {
Name string `json:"name", validate:"required"`
Producer *string `json:"producer,omitempty"`
ProductId *string `json:"product_id,omitempty"`
MiscellaneousBaseType MiscellaneousBaseType `json:"type", validate:"required"`
}
type MiscellaneousBaseType string
func (s *MiscellaneousBaseType) UnmarshalJSON(b []byte) error {
var v string
err := json.Unmarshal(b, &v)
if err != nil {
return err
}
*s = MiscellaneousBaseType(v)
switch *s {
case MiscellaneousBaseType_Spice:
return nil
case MiscellaneousBaseType_Fining:
return nil
case MiscellaneousBaseType_WaterAgent:
return nil
case MiscellaneousBaseType_Herb:
return nil
case MiscellaneousBaseType_Flavor:
return nil
case MiscellaneousBaseType_Wood:
return nil
case MiscellaneousBaseType_Other:
return nil
}
return fmt.Errorf("MiscellaneousBaseType: value '%v' does not match any value", v)
}
const (
MiscellaneousBaseType_Spice MiscellaneousBaseType = "spice"
MiscellaneousBaseType_Fining MiscellaneousBaseType = "fining"
MiscellaneousBaseType_WaterAgent MiscellaneousBaseType = "water agent"
MiscellaneousBaseType_Herb MiscellaneousBaseType = "herb"
MiscellaneousBaseType_Flavor MiscellaneousBaseType = "flavor"
MiscellaneousBaseType_Wood MiscellaneousBaseType = "wood"
MiscellaneousBaseType_Other MiscellaneousBaseType = "other"
)
type MiscellaneousInventoryType struct {
Amount MiscellaneousInventoryTypeAmount `json:"amount", validate:"required,oneof"`
}
func (s *MiscellaneousInventoryType) UnmarshalJSON(b []byte) error {
m := map[string]json.RawMessage{}
if err := json.Unmarshal(b, &m); err != nil {
return nil
}
miscellaneousInventoryTypeAmount := func() MiscellaneousInventoryTypeAmount {
raw, ok := m["amount"]
if !ok {
return nil
}
var volumeType VolumeType
if err := json.Unmarshal(raw, &volumeType); err == nil {
return &volumeType
}
var massType MassType
if err := json.Unmarshal(raw, &massType); err == nil {
return &massType
}
var unitType UnitType
if err := json.Unmarshal(raw, &unitType); err == nil {
return &unitType
}
return nil
}
type Alias MiscellaneousInventoryType
aux := &struct {
Amount MiscellaneousInventoryTypeAmount `json:"amount", validate:"required,oneof"`
*Alias
}{
Amount: miscellaneousInventoryTypeAmount(),
Alias: (*Alias)(s),
}
if err := json.Unmarshal(b, &aux); err != nil {
return err
}
s.Amount = aux.Amount
return nil
}
// MiscellaneousInventoryTypeAmount
type MiscellaneousInventoryTypeAmount interface {
MiscellaneousInventoryTypeamount()
}
// MiscellaneousType collects the attributes of an ingredient to store as record information.
type MiscellaneousType struct {
Inventory *MiscellaneousInventoryType `json:"inventory,omitempty"`
Name *string `json:"name,omitempty"`
Producer *string `json:"producer,omitempty"`
ProductId *string `json:"product_id,omitempty"`
MiscellaneousBaseType *MiscellaneousBaseType `json:"type,omitempty"`
// Used to describe the purpose of the miscellaneous ingredient, e.g. whirlfloc is used for clarity.
UseFor *string `json:"use_for,omitempty"`
Notes *string `json:"notes,omitempty"`
}