Skip to content

Commit

Permalink
Use value receiver for MarshalText (#37)
Browse files Browse the repository at this point in the history
* Use value receiver for MarshalText

* Switch to same version of go-bindata installed by homebrew
  • Loading branch information
pswaminathan authored and abice committed Dec 11, 2019
1 parent 99771f1 commit 304de84
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all: build fmt test example cover install

.PHONY: install-deps
install-deps:
go install -v github.com/jteeuwen/go-bindata/go-bindata
go install -v github.com/kevinburke/go-bindata/go-bindata
go install -v golang.org/x/tools/cmd/cover
go install -v github.com/mattn/goveralls
go mod vendor
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/abice/go-enum)](https://goreportcard.com/report/github.com/abice/go-enum)
[![Coverage Status](https://coveralls.io/repos/github/abice/go-enum/badge.svg)](https://coveralls.io/github/abice/go-enum)
[![GoDoc](https://godoc.org/github.com/abice/go-enum?status.svg)](https://godoc.org/github.com/abice/go-enum)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)

An enum generator for go

Expand All @@ -25,7 +25,7 @@ Options:
-f, --file *The file(s) to generate enums. Use more than one flag for more files.
--noprefix Prevents the constants generated from having the Enum as a prefix.
--lower Adds lowercase variants of the enum strings for lookup.
--marshal Adds text marshalling functions.
--marshal Adds text (and inherently json) marshalling functions.
--sql Adds SQL database scan and value functions.
--flag Adds golang flag functions.
--prefix Replaces the prefix with a user one.
Expand Down
2 changes: 1 addition & 1 deletion example/color_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/commented_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/example_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions generator/.snapshots/generator-TestExampleFile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=48) "func (x *Animal) MarshalText() ([]byte, error) {",
(string) (len=47) "func (x Animal) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -164,7 +164,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=47) "func (x *Cases) MarshalText() ([]byte, error) {",
(string) (len=46) "func (x Cases) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -286,7 +286,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=47) "func (x *Color) MarshalText() ([]byte, error) {",
(string) (len=46) "func (x Color) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -409,7 +409,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=58) "func (x *ColorWithComment) MarshalText() ([]byte, error) {",
(string) (len=57) "func (x ColorWithComment) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -532,7 +532,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=59) "func (x *ColorWithComment2) MarshalText() ([]byte, error) {",
(string) (len=58) "func (x ColorWithComment2) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -674,7 +674,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=59) "func (x *ColorWithComment3) MarshalText() ([]byte, error) {",
(string) (len=58) "func (x ColorWithComment3) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -815,7 +815,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=59) "func (x *ColorWithComment4) MarshalText() ([]byte, error) {",
(string) (len=58) "func (x ColorWithComment4) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -917,7 +917,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=47) "func (x *Model) MarshalText() ([]byte, error) {",
(string) (len=46) "func (x Model) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -1039,7 +1039,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=52) "func (x *Sanitizing) MarshalText() ([]byte, error) {",
(string) (len=51) "func (x Sanitizing) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -1137,7 +1137,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=46) "func (x *Soda) MarshalText() ([]byte, error) {",
(string) (len=45) "func (x Soda) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -1229,7 +1229,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=54) "func (x *StartNotZero) MarshalText() ([]byte, error) {",
(string) (len=53) "func (x StartNotZero) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down
22 changes: 11 additions & 11 deletions generator/.snapshots/generator-TestNoPrefixExampleFile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=48) "func (x *Animal) MarshalText() ([]byte, error) {",
(string) (len=47) "func (x Animal) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -127,7 +127,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=47) "func (x *Cases) MarshalText() ([]byte, error) {",
(string) (len=46) "func (x Cases) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -222,7 +222,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=47) "func (x *Color) MarshalText() ([]byte, error) {",
(string) (len=46) "func (x Color) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -318,7 +318,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=58) "func (x *ColorWithComment) MarshalText() ([]byte, error) {",
(string) (len=57) "func (x ColorWithComment) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -414,7 +414,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=59) "func (x *ColorWithComment2) MarshalText() ([]byte, error) {",
(string) (len=58) "func (x ColorWithComment2) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -526,7 +526,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=59) "func (x *ColorWithComment3) MarshalText() ([]byte, error) {",
(string) (len=58) "func (x ColorWithComment3) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -638,7 +638,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=59) "func (x *ColorWithComment4) MarshalText() ([]byte, error) {",
(string) (len=58) "func (x ColorWithComment4) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -717,7 +717,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=47) "func (x *Model) MarshalText() ([]byte, error) {",
(string) (len=46) "func (x Model) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -812,7 +812,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=52) "func (x *Sanitizing) MarshalText() ([]byte, error) {",
(string) (len=51) "func (x Sanitizing) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -887,7 +887,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=46) "func (x *Soda) MarshalText() ([]byte, error) {",
(string) (len=45) "func (x Soda) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -957,7 +957,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=54) "func (x *StartNotZero) MarshalText() ([]byte, error) {",
(string) (len=53) "func (x StartNotZero) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=48) "func (x *Animal) MarshalText() ([]byte, error) {",
(string) (len=47) "func (x Animal) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -127,7 +127,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=47) "func (x *Cases) MarshalText() ([]byte, error) {",
(string) (len=46) "func (x Cases) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -222,7 +222,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=47) "func (x *Color) MarshalText() ([]byte, error) {",
(string) (len=46) "func (x Color) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -318,7 +318,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=58) "func (x *ColorWithComment) MarshalText() ([]byte, error) {",
(string) (len=57) "func (x ColorWithComment) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -414,7 +414,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=59) "func (x *ColorWithComment2) MarshalText() ([]byte, error) {",
(string) (len=58) "func (x ColorWithComment2) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -526,7 +526,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=59) "func (x *ColorWithComment3) MarshalText() ([]byte, error) {",
(string) (len=58) "func (x ColorWithComment3) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -638,7 +638,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=59) "func (x *ColorWithComment4) MarshalText() ([]byte, error) {",
(string) (len=58) "func (x ColorWithComment4) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -717,7 +717,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=47) "func (x *Model) MarshalText() ([]byte, error) {",
(string) (len=46) "func (x Model) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -812,7 +812,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=52) "func (x *Sanitizing) MarshalText() ([]byte, error) {",
(string) (len=51) "func (x Sanitizing) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -887,7 +887,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=46) "func (x *Soda) MarshalText() ([]byte, error) {",
(string) (len=45) "func (x Soda) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down Expand Up @@ -957,7 +957,7 @@
(string) (len=1) "}",
(string) "",
(string) (len=52) "// MarshalText implements the text marshaller method",
(string) (len=54) "func (x *StartNotZero) MarshalText() ([]byte, error) {",
(string) (len=53) "func (x StartNotZero) MarshalText() ([]byte, error) {",
(string) (len=31) "\treturn []byte(x.String()), nil",
(string) (len=1) "}",
(string) "",
Expand Down
Loading

0 comments on commit 304de84

Please sign in to comment.