48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// generated by jsonenums -type=ShirtSize; DO NOT EDIT
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
func (r ShirtSize) MarshalJSON() ([]byte, error) {
|
|
if s, ok := interface{}(r).(fmt.Stringer); ok {
|
|
return json.Marshal(s.String())
|
|
}
|
|
s, ok := map[ShirtSize]string{
|
|
NA: "NA", XS: "XS", S: "S", M: "M", L: "L", XL: "XL",
|
|
}[r]
|
|
if !ok {
|
|
return nil, fmt.Errorf("invalid ShirtSize: %d", r)
|
|
}
|
|
return json.Marshal(s)
|
|
}
|
|
|
|
var _ShirtSizeNameToValue = map[string]ShirtSize{
|
|
"NA": NA, "XS": XS, "S": S, "M": M, "L": L, "XL": XL,
|
|
}
|
|
|
|
func init() {
|
|
var v ShirtSize
|
|
if _, ok := interface{}(v).(fmt.Stringer); ok {
|
|
_ShirtSizeNameToValue = map[string]ShirtSize{
|
|
interface{}(NA).(fmt.Stringer).String(): NA, interface{}(XS).(fmt.Stringer).String(): XS, interface{}(S).(fmt.Stringer).String(): S, interface{}(M).(fmt.Stringer).String(): M, interface{}(L).(fmt.Stringer).String(): L, interface{}(XL).(fmt.Stringer).String(): XL,
|
|
}
|
|
}
|
|
}
|
|
|
|
func (r *ShirtSize) UnmarshalJSON(data []byte) error {
|
|
var s string
|
|
if err := json.Unmarshal(data, &s); err != nil {
|
|
return fmt.Errorf("ShirtSize should be a string, got %s", data)
|
|
}
|
|
v, ok := _ShirtSizeNameToValue[s]
|
|
if !ok {
|
|
return fmt.Errorf("invalid ShirtSize %q", s)
|
|
}
|
|
*r = v
|
|
return nil
|
|
}
|