forked from mirror/enumer
Merge pull request #28 from MrGossett/MrGossett/comment-json-yaml
Comments for JSON and YAML marshaler methods
This commit is contained in:
commit
60ace443ec
|
@ -40,10 +40,12 @@ func (g *Generator) buildValueToNameMap(runs [][]Value, typeName string, runsThr
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const jsonMethods = `
|
const jsonMethods = `
|
||||||
|
// MarshalJSON implements the json.Marshaler interface for %[1]s
|
||||||
func (i %[1]s) MarshalJSON() ([]byte, error) {
|
func (i %[1]s) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(i.String())
|
return json.Marshal(i.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON implements the json.Unmarshaler interface for %[1]s
|
||||||
func (i *%[1]s) UnmarshalJSON(data []byte) error {
|
func (i *%[1]s) UnmarshalJSON(data []byte) error {
|
||||||
var s string
|
var s string
|
||||||
if err := json.Unmarshal(data, &s); err != nil {
|
if err := json.Unmarshal(data, &s); err != nil {
|
||||||
|
@ -81,10 +83,12 @@ func (g *Generator) buildTextMethods(runs [][]Value, typeName string, runsThresh
|
||||||
// Arguments to format are:
|
// Arguments to format are:
|
||||||
// [1]: type name
|
// [1]: type name
|
||||||
const yamlMethods = `
|
const yamlMethods = `
|
||||||
|
// MarshalYAML implements a YAML Marshaler interface for %[1]s
|
||||||
func (i %[1]s) MarshalYAML() (interface{}, error) {
|
func (i %[1]s) MarshalYAML() (interface{}, error) {
|
||||||
return i.String(), nil
|
return i.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalYAML implements a YAML Unmarshaler interface for %[1]s
|
||||||
func (i *%[1]s) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (i *%[1]s) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
var s string
|
var s string
|
||||||
if err := unmarshal(&s); err != nil {
|
if err := unmarshal(&s); err != nil {
|
||||||
|
|
|
@ -443,10 +443,12 @@ func PrimeString(s string) (Prime, error) {
|
||||||
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements the json.Marshaler interface for Prime
|
||||||
func (i Prime) MarshalJSON() ([]byte, error) {
|
func (i Prime) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(i.String())
|
return json.Marshal(i.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON implements the json.Unmarshaler interface for Prime
|
||||||
func (i *Prime) UnmarshalJSON(data []byte) error {
|
func (i *Prime) UnmarshalJSON(data []byte) error {
|
||||||
var s string
|
var s string
|
||||||
if err := json.Unmarshal(data, &s); err != nil {
|
if err := json.Unmarshal(data, &s); err != nil {
|
||||||
|
@ -610,10 +612,12 @@ func PrimeString(s string) (Prime, error) {
|
||||||
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalYAML implements a YAML Marshaler interface for Prime
|
||||||
func (i Prime) MarshalYAML() (interface{}, error) {
|
func (i Prime) MarshalYAML() (interface{}, error) {
|
||||||
return i.String(), nil
|
return i.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalYAML implements a YAML Unmarshaler interface for Prime
|
||||||
func (i *Prime) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (i *Prime) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
var s string
|
var s string
|
||||||
if err := unmarshal(&s); err != nil {
|
if err := unmarshal(&s); err != nil {
|
||||||
|
@ -795,10 +799,12 @@ func PrimeString(s string) (Prime, error) {
|
||||||
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements the json.Marshaler interface for Prime
|
||||||
func (i Prime) MarshalJSON() ([]byte, error) {
|
func (i Prime) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(i.String())
|
return json.Marshal(i.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON implements the json.Unmarshaler interface for Prime
|
||||||
func (i *Prime) UnmarshalJSON(data []byte) error {
|
func (i *Prime) UnmarshalJSON(data []byte) error {
|
||||||
var s string
|
var s string
|
||||||
if err := json.Unmarshal(data, &s); err != nil {
|
if err := json.Unmarshal(data, &s); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue