Comments for JSON and YAML marshaler methods

`go vet` will complain when an exported method is not properly
documented. This change adds comments to the generated `MarshalJSON`,
`UnmarshalJSON`, `MarshalYAML`, and `UnmarshalYAML` methods to satisfy
`go vet`.

As of go 1.10, the go test command now automatically runs go vet on the
package being tested. Complaints from `go vet` are treated like build
errors and prevent execution of the test. This means that generated code
that is not properly documented will prevent test execution.

[1]: https://golang.org/doc/go1.10#test-vet
This commit is contained in:
Tim Gossett 2018-02-19 22:20:31 -05:00
parent f3fec002f1
commit f283678ee0
No known key found for this signature in database
GPG Key ID: 6708169C08D3CCF0
2 changed files with 11 additions and 1 deletions

View File

@ -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 {
@ -63,10 +65,12 @@ func (g *Generator) buildJSONMethods(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 {

View File

@ -440,10 +440,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 {
@ -526,10 +528,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 {
@ -711,10 +715,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 {