-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhop.go
283 lines (243 loc) · 9.01 KB
/
hop.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// Code generated by jsonschema. DO NOT EDIT.
package beerjson
import "encoding/json"
import "fmt"
// ID: https://raw.githubusercontent.com/beerjson/beerjson/master/json/hop.json
// HopAdditionType collects the attributes of each hop ingredient for use in a recipe hop bil.
type HopAdditionType struct {
Year *string `json:"year,omitempty"`
AlphaAcid *PercentType `json:"alpha_acid,omitempty"`
BetaAcid *PercentType `json:"beta_acid,omitempty"`
Name *string `json:"name,omitempty"`
ProductId *string `json:"product_id,omitempty"`
Origin *string `json:"origin,omitempty"`
HopVarietyBaseForm *HopVarietyBaseForm `json:"form,omitempty"`
Producer *string `json:"producer,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", validate:"required"`
Amount HopAdditionTypeAmount `json:"amount", validate:"required,oneof"`
}
func (s *HopAdditionType) UnmarshalJSON(b []byte) error {
m := map[string]json.RawMessage{}
if err := json.Unmarshal(b, &m); err != nil {
return nil
}
hopAdditionTypeAmount := func() HopAdditionTypeAmount {
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
}
return nil
}
type Alias HopAdditionType
aux := &struct {
Amount HopAdditionTypeAmount `json:"amount", validate:"required,oneof"`
*Alias
}{
Amount: hopAdditionTypeAmount(),
Alias: (*Alias)(s),
}
if err := json.Unmarshal(b, &aux); err != nil {
return err
}
s.Amount = aux.Amount
return nil
}
// HopAdditionTypeAmount
type HopAdditionTypeAmount interface {
HopAdditionTypeamount()
}
type HopInventoryType struct {
Amount HopInventoryTypeAmount `json:"amount,omitempty", validate:"oneof"`
}
func (s *HopInventoryType) UnmarshalJSON(b []byte) error {
m := map[string]json.RawMessage{}
if err := json.Unmarshal(b, &m); err != nil {
return nil
}
hopInventoryTypeAmount := func() HopInventoryTypeAmount {
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
}
return nil
}
type Alias HopInventoryType
aux := &struct {
Amount HopInventoryTypeAmount `json:"amount,omitempty", validate:"oneof"`
*Alias
}{
Amount: hopInventoryTypeAmount(),
Alias: (*Alias)(s),
}
if err := json.Unmarshal(b, &aux); err != nil {
return err
}
s.Amount = aux.Amount
return nil
}
// HopInventoryTypeAmount
type HopInventoryTypeAmount interface {
HopInventoryTypeamount()
}
// HopVarietyBase provides unique properties to identify individual records of a hop variety.
type HopVarietyBase struct {
Name string `json:"name", validate:"required"`
Producer *string `json:"producer,omitempty"`
ProductId *string `json:"product_id,omitempty"`
Origin *string `json:"origin,omitempty"`
Year *string `json:"year,omitempty"`
HopVarietyBaseForm *HopVarietyBaseForm `json:"form,omitempty"`
AlphaAcid PercentType `json:"alpha_acid", validate:"required"`
BetaAcid *PercentType `json:"beta_acid,omitempty"`
}
type HopVarietyBaseForm string
func (s *HopVarietyBaseForm) UnmarshalJSON(b []byte) error {
var v string
err := json.Unmarshal(b, &v)
if err != nil {
return err
}
*s = HopVarietyBaseForm(v)
switch *s {
case HopVarietyBaseForm_Extract:
return nil
case HopVarietyBaseForm_Leaf:
return nil
case HopVarietyBaseForm_LeafWet:
return nil
case HopVarietyBaseForm_Pellet:
return nil
case HopVarietyBaseForm_Powder:
return nil
case HopVarietyBaseForm_Plug:
return nil
}
return fmt.Errorf("HopVarietyBaseForm: value '%v' does not match any value", v)
}
const (
HopVarietyBaseForm_Extract HopVarietyBaseForm = "extract"
HopVarietyBaseForm_Leaf HopVarietyBaseForm = "leaf"
HopVarietyBaseForm_LeafWet HopVarietyBaseForm = "leaf (wet)"
HopVarietyBaseForm_Pellet HopVarietyBaseForm = "pellet"
HopVarietyBaseForm_Powder HopVarietyBaseForm = "powder"
HopVarietyBaseForm_Plug HopVarietyBaseForm = "plug"
)
// Used to differentiate which IBU formula is being used in a recipe. If formula is modified in any way, eg to support whirlpool/flameout additions etc etc, please use `Other` for transparency.
type IBUEstimateType struct {
Method *IBUMethodType `json:"method,omitempty"`
}
type IBUMethodType string
func (s *IBUMethodType) UnmarshalJSON(b []byte) error {
var v string
err := json.Unmarshal(b, &v)
if err != nil {
return err
}
*s = IBUMethodType(v)
switch *s {
case IBUMethodType_Rager:
return nil
case IBUMethodType_Tinseth:
return nil
case IBUMethodType_Garetz:
return nil
case IBUMethodType_Other:
return nil
}
return fmt.Errorf("IBUMethodType: value '%v' does not match any value", v)
}
const (
IBUMethodType_Rager IBUMethodType = "Rager"
IBUMethodType_Tinseth IBUMethodType = "Tinseth"
IBUMethodType_Garetz IBUMethodType = "Garetz"
IBUMethodType_Other IBUMethodType = "Other"
)
// oil_content collects all information of a hop variety pertaining to oil content, polyphenols, and thiols. Each individual compound is expressed as a percent of the total oil measurement.
type OilContentType struct {
BPinene *PercentType `json:"b_pinene,omitempty"`
Pinene *PercentType `json:"pinene,omitempty"`
// The total amount of oil, including hydrocarbons, esters, and terpene alcohols in units of ml of oil per 100g of hop mass.
TotalOilMlPer100g *float64 `json:"total_oil_ml_per_100g,omitempty"`
Humulene *PercentType `json:"humulene,omitempty"`
Nerol *PercentType `json:"nerol,omitempty"`
Xanthohumol *PercentType `json:"xanthohumol,omitempty"`
Caryophyllene *PercentType `json:"caryophyllene,omitempty"`
Farnesene *PercentType `json:"farnesene,omitempty"`
Limonene *PercentType `json:"limonene,omitempty"`
Polyphenols *PercentType `json:"polyphenols,omitempty"`
Cohumulone *PercentType `json:"cohumulone,omitempty"`
Myrcene *PercentType `json:"myrcene,omitempty"`
Geraniol *PercentType `json:"geraniol,omitempty"`
Linalool *PercentType `json:"linalool,omitempty"`
}
// VarietyInformation collects the attributes of a hop variety to store as record information.
type VarietyInformation struct {
AlphaAcid *PercentType `json:"alpha_acid,omitempty"`
VarietyInformationType *VarietyInformationType `json:"type,omitempty"`
// Defined as the percentage of hop alpha lost in 6 months of storage.
PercentLost *PercentType `json:"percent_lost,omitempty"`
Year *string `json:"year,omitempty"`
Notes *string `json:"notes,omitempty"`
// Oil Content information object.
OilContent *OilContentType `json:"oil_content,omitempty"`
Producer *string `json:"producer,omitempty"`
ProductId *string `json:"product_id,omitempty"`
HopVarietyBaseForm *HopVarietyBaseForm `json:"form,omitempty"`
Name *string `json:"name,omitempty"`
Substitutes *string `json:"substitutes,omitempty"`
Inventory *HopInventoryType `json:"inventory,omitempty"`
Origin *string `json:"origin,omitempty"`
BetaAcid *PercentType `json:"beta_acid,omitempty"`
}
type VarietyInformationType string
func (s *VarietyInformationType) UnmarshalJSON(b []byte) error {
var v string
err := json.Unmarshal(b, &v)
if err != nil {
return err
}
*s = VarietyInformationType(v)
switch *s {
case VarietyInformationType_Aroma:
return nil
case VarietyInformationType_Bittering:
return nil
case VarietyInformationType_Flavor:
return nil
case VarietyInformationType_AromaBittering:
return nil
case VarietyInformationType_BitteringFlavor:
return nil
case VarietyInformationType_AromaFlavor:
return nil
case VarietyInformationType_AromaBitteringFlavor:
return nil
}
return fmt.Errorf("VarietyInformationType: value '%v' does not match any value", v)
}
const (
VarietyInformationType_Aroma VarietyInformationType = "aroma"
VarietyInformationType_Bittering VarietyInformationType = "bittering"
VarietyInformationType_Flavor VarietyInformationType = "flavor"
VarietyInformationType_AromaBittering VarietyInformationType = "aroma/bittering"
VarietyInformationType_BitteringFlavor VarietyInformationType = "bittering/flavor"
VarietyInformationType_AromaFlavor VarietyInformationType = "aroma/flavor"
VarietyInformationType_AromaBitteringFlavor VarietyInformationType = "aroma/bittering/flavor"
)