Sample generated output from example struct
This commit is contained in:
parent
28b78f4481
commit
465b153cfd
78
example/testcasing_jsonenums.go
Normal file
78
example/testcasing_jsonenums.go
Normal file
@ -0,0 +1,78 @@
|
||||
// generated by jsonenums -type=TestCasing; DO NOT EDIT
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
_TestCasingNameToValue = map[string]TestCasing{
|
||||
"case_madness_a": caseMadnessA,
|
||||
"case_ma_dn_e_es_b": caseMaDnEEsB,
|
||||
"normal_case_example": normalCaseExample,
|
||||
}
|
||||
|
||||
_TestCasingValueToName = map[TestCasing]string{
|
||||
caseMadnessA: "case_madness_a",
|
||||
caseMaDnEEsB: "case_ma_dn_e_es_b",
|
||||
normalCaseExample: "normal_case_example",
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
var v TestCasing
|
||||
if _, ok := interface{}(v).(fmt.Stringer); ok {
|
||||
_TestCasingNameToValue = map[string]TestCasing{
|
||||
interface{}(caseMadnessA).(fmt.Stringer).String(): caseMadnessA,
|
||||
interface{}(caseMaDnEEsB).(fmt.Stringer).String(): caseMaDnEEsB,
|
||||
interface{}(normalCaseExample).(fmt.Stringer).String(): normalCaseExample,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalJSON is generated so TestCasing satisfies json.Marshaler.
|
||||
func (r TestCasing) MarshalJSON() ([]byte, error) {
|
||||
if s, ok := interface{}(r).(fmt.Stringer); ok {
|
||||
return json.Marshal(s.String())
|
||||
}
|
||||
s, ok := _TestCasingValueToName[r]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid TestCasing: %d", r)
|
||||
}
|
||||
return json.Marshal(s)
|
||||
}
|
||||
|
||||
// UnmarshalJSON is generated so TestCasing satisfies json.Unmarshaler.
|
||||
func (r *TestCasing) UnmarshalJSON(data []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(data, &s); err != nil {
|
||||
return fmt.Errorf("TestCasing should be a string, got %s", data)
|
||||
}
|
||||
v, ok := _TestCasingNameToValue[s]
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid TestCasing %q", s)
|
||||
}
|
||||
*r = v
|
||||
return nil
|
||||
}
|
||||
|
||||
//Scan an input string into this structure for use with GORP
|
||||
func (r *TestCasing) Scan(i interface{}) error {
|
||||
switch i.(type) {
|
||||
case string:
|
||||
r.UnmarshalJSON([]byte(i.(string)))
|
||||
default:
|
||||
return errors.Errorf("Can't scan %T into type %T", i, r)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r TestCasing) Value() (driver.Value, error) {
|
||||
bytes, err := r.MarshalJSON()
|
||||
return string(bytes), err
|
||||
}
|
Loading…
Reference in New Issue
Block a user