From aba70a004c374fd2cec27c16313c353f79bb813b Mon Sep 17 00:00:00 2001 From: Mark Phelps Date: Mon, 3 May 2021 16:21:42 -0400 Subject: [PATCH 1/3] Dont generate json methods for complex types --- bool.go | 2 +- byte.go | 2 +- cmd/optional/main.go | 3 +++ complex128.go | 26 +------------------------- complex64.go | 26 +------------------------- error.go | 2 +- float32.go | 2 +- float64.go | 2 +- int.go | 2 +- int16.go | 2 +- int32.go | 2 +- int64.go | 2 +- int8.go | 2 +- rune.go | 2 +- string.go | 2 +- uint.go | 2 +- uint16.go | 2 +- uint32.go | 2 +- uint64.go | 2 +- uint8.go | 2 +- uintptr.go | 2 +- 21 files changed, 23 insertions(+), 68 deletions(-) diff --git a/bool.go b/bool.go index fbc6f2b..05b1bcb 100644 --- a/bool.go +++ b/bool.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:53.447681 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:06.173184 +0000 UTC package optional diff --git a/byte.go b/byte.go index 39409d8..8c03ff6 100644 --- a/byte.go +++ b/byte.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:53.79355 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:06.605682 +0000 UTC package optional diff --git a/cmd/optional/main.go b/cmd/optional/main.go index 0c8ce56..1b975e9 100644 --- a/cmd/optional/main.go +++ b/cmd/optional/main.go @@ -179,6 +179,8 @@ func ({{ .VariableName }} {{ .OutputName }}) If(fn func({{ .TypeName }})) { } } +{{- if and (ne .TypeName "complex64") (ne .TypeName "complex128") }} + func ({{ .VariableName }} {{ .OutputName }}) MarshalJSON() ([]byte, error) { if {{ .VariableName }}.Present() { return json.Marshal({{ .VariableName }}.value) @@ -202,4 +204,5 @@ func ({{ .VariableName }} *{{ .OutputName }}) UnmarshalJSON(data []byte) error { {{ .VariableName }}.value = &value return nil } +{{- end }} ` diff --git a/complex128.go b/complex128.go index b85dfbe..ff01e0d 100644 --- a/complex128.go +++ b/complex128.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:54.128811 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:07.610327 +0000 UTC package optional @@ -51,27 +51,3 @@ func (c Complex128) If(fn func(complex128)) { fn(*c.value) } } - -func (c Complex128) MarshalJSON() ([]byte, error) { - if c.Present() { - return json.Marshal(c.value) - } - return json.Marshal(nil) -} - -func (c *Complex128) UnmarshalJSON(data []byte) error { - - if string(data) == "null" { - c.value = nil - return nil - } - - var value complex128 - - if err := json.Unmarshal(data, &value); err != nil { - return err - } - - c.value = &value - return nil -} diff --git a/complex64.go b/complex64.go index 04d5ee5..11ed4e1 100644 --- a/complex64.go +++ b/complex64.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:54.464548 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:08.010171 +0000 UTC package optional @@ -51,27 +51,3 @@ func (c Complex64) If(fn func(complex64)) { fn(*c.value) } } - -func (c Complex64) MarshalJSON() ([]byte, error) { - if c.Present() { - return json.Marshal(c.value) - } - return json.Marshal(nil) -} - -func (c *Complex64) UnmarshalJSON(data []byte) error { - - if string(data) == "null" { - c.value = nil - return nil - } - - var value complex64 - - if err := json.Unmarshal(data, &value); err != nil { - return err - } - - c.value = &value - return nil -} diff --git a/error.go b/error.go index bc79ddc..5d98d62 100644 --- a/error.go +++ b/error.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:54.804224 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:08.402824 +0000 UTC package optional diff --git a/float32.go b/float32.go index 9f42c2c..44f72d6 100644 --- a/float32.go +++ b/float32.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:55.1819 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:08.807462 +0000 UTC package optional diff --git a/float64.go b/float64.go index 15966b6..b3c2ae6 100644 --- a/float64.go +++ b/float64.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:55.521255 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:09.200833 +0000 UTC package optional diff --git a/int.go b/int.go index caead99..3575f5f 100644 --- a/int.go +++ b/int.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:55.863991 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:09.59574 +0000 UTC package optional diff --git a/int16.go b/int16.go index 9532996..1844611 100644 --- a/int16.go +++ b/int16.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:56.212093 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:09.983309 +0000 UTC package optional diff --git a/int32.go b/int32.go index 07c212d..54441c2 100644 --- a/int32.go +++ b/int32.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:56.641482 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:10.368844 +0000 UTC package optional diff --git a/int64.go b/int64.go index 7f8f01c..3bdbd26 100644 --- a/int64.go +++ b/int64.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:57.002648 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:10.762212 +0000 UTC package optional diff --git a/int8.go b/int8.go index 182f814..c999e12 100644 --- a/int8.go +++ b/int8.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:57.555216 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:11.167814 +0000 UTC package optional diff --git a/rune.go b/rune.go index 469de67..21ce5e9 100644 --- a/rune.go +++ b/rune.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:57.969673 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:11.55085 +0000 UTC package optional diff --git a/string.go b/string.go index 19e67c1..08d0b6a 100644 --- a/string.go +++ b/string.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:58.516631 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:11.941038 +0000 UTC package optional diff --git a/uint.go b/uint.go index 33e93e3..a8e8898 100644 --- a/uint.go +++ b/uint.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:58.898667 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:12.325449 +0000 UTC package optional diff --git a/uint16.go b/uint16.go index 428ecbf..641d1b1 100644 --- a/uint16.go +++ b/uint16.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:59.455534 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:12.71755 +0000 UTC package optional diff --git a/uint32.go b/uint32.go index 5fa2ebf..ae79342 100644 --- a/uint32.go +++ b/uint32.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:29:59.856381 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:13.10178 +0000 UTC package optional diff --git a/uint64.go b/uint64.go index f0d79a4..f3bb1c3 100644 --- a/uint64.go +++ b/uint64.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:30:00.317311 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:13.48401 +0000 UTC package optional diff --git a/uint8.go b/uint8.go index 9b2be7f..2fbb332 100644 --- a/uint8.go +++ b/uint8.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:30:00.699077 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:13.907475 +0000 UTC package optional diff --git a/uintptr.go b/uintptr.go index af79fef..1b734cd 100644 --- a/uintptr.go +++ b/uintptr.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 14:30:01.109101 +0000 UTC +// This file was generated by robots at 2021-05-03 20:21:14.289427 +0000 UTC package optional From 17b228c30ff7027579927a405411f00273e59e76 Mon Sep 17 00:00:00 2001 From: Mark Phelps Date: Mon, 3 May 2021 16:25:14 -0400 Subject: [PATCH 2/3] Fix --- bool.go | 2 +- byte.go | 2 +- cmd/optional/main.go | 2 ++ cmd/optional/testdata/optional_bar.go | 2 +- cmd/optional/testdata/optional_foo.go | 2 +- cmd/optional/testdata/string.go | 2 +- complex128.go | 3 +-- complex64.go | 3 +-- error.go | 2 +- float32.go | 2 +- float64.go | 2 +- int.go | 2 +- int16.go | 2 +- int32.go | 2 +- int64.go | 2 +- int8.go | 2 +- rune.go | 2 +- string.go | 2 +- uint.go | 2 +- uint16.go | 2 +- uint32.go | 2 +- uint64.go | 2 +- uint8.go | 2 +- uintptr.go | 2 +- 24 files changed, 25 insertions(+), 25 deletions(-) diff --git a/bool.go b/bool.go index 05b1bcb..1c93937 100644 --- a/bool.go +++ b/bool.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:06.173184 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:37.859274 +0000 UTC package optional diff --git a/byte.go b/byte.go index 8c03ff6..c9335a4 100644 --- a/byte.go +++ b/byte.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:06.605682 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:38.247279 +0000 UTC package optional diff --git a/cmd/optional/main.go b/cmd/optional/main.go index 1b975e9..4e4c12b 100644 --- a/cmd/optional/main.go +++ b/cmd/optional/main.go @@ -131,7 +131,9 @@ const tmpl = `// Code generated by go generate package {{ .PackageName }} import ( +{{- if and (ne .TypeName "complex64") (ne .TypeName "complex128") }} "encoding/json" +{{- end }} "errors" ) diff --git a/cmd/optional/testdata/optional_bar.go b/cmd/optional/testdata/optional_bar.go index 01c9307..c796b37 100644 --- a/cmd/optional/testdata/optional_bar.go +++ b/cmd/optional/testdata/optional_bar.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 17:57:17.641444 +0000 UTC +// This file was generated by robots at 2021-05-03 20:22:57.093409 +0000 UTC package bar diff --git a/cmd/optional/testdata/optional_foo.go b/cmd/optional/testdata/optional_foo.go index 18a2c24..a60f7e9 100644 --- a/cmd/optional/testdata/optional_foo.go +++ b/cmd/optional/testdata/optional_foo.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 17:57:17.640425 +0000 UTC +// This file was generated by robots at 2021-05-03 20:22:57.092747 +0000 UTC package foo diff --git a/cmd/optional/testdata/string.go b/cmd/optional/testdata/string.go index 64074b9..8ed6bb5 100644 --- a/cmd/optional/testdata/string.go +++ b/cmd/optional/testdata/string.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-12-06 17:57:17.639386 +0000 UTC +// This file was generated by robots at 2021-05-03 20:22:57.091816 +0000 UTC package optional diff --git a/complex128.go b/complex128.go index ff01e0d..2200dc9 100644 --- a/complex128.go +++ b/complex128.go @@ -1,10 +1,9 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:07.610327 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:38.633502 +0000 UTC package optional import ( - "encoding/json" "errors" ) diff --git a/complex64.go b/complex64.go index 11ed4e1..9d07d4a 100644 --- a/complex64.go +++ b/complex64.go @@ -1,10 +1,9 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:08.010171 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:39.017904 +0000 UTC package optional import ( - "encoding/json" "errors" ) diff --git a/error.go b/error.go index 5d98d62..ff6c62e 100644 --- a/error.go +++ b/error.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:08.402824 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:39.403027 +0000 UTC package optional diff --git a/float32.go b/float32.go index 44f72d6..bdff83b 100644 --- a/float32.go +++ b/float32.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:08.807462 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:39.935633 +0000 UTC package optional diff --git a/float64.go b/float64.go index b3c2ae6..640cbe8 100644 --- a/float64.go +++ b/float64.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:09.200833 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:41.277145 +0000 UTC package optional diff --git a/int.go b/int.go index 3575f5f..bf9fcae 100644 --- a/int.go +++ b/int.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:09.59574 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:41.676284 +0000 UTC package optional diff --git a/int16.go b/int16.go index 1844611..37ab9c0 100644 --- a/int16.go +++ b/int16.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:09.983309 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:42.065863 +0000 UTC package optional diff --git a/int32.go b/int32.go index 54441c2..8dd9690 100644 --- a/int32.go +++ b/int32.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:10.368844 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:42.453259 +0000 UTC package optional diff --git a/int64.go b/int64.go index 3bdbd26..dbfd972 100644 --- a/int64.go +++ b/int64.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:10.762212 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:42.850127 +0000 UTC package optional diff --git a/int8.go b/int8.go index c999e12..f63b049 100644 --- a/int8.go +++ b/int8.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:11.167814 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:43.246461 +0000 UTC package optional diff --git a/rune.go b/rune.go index 21ce5e9..bc5e8cc 100644 --- a/rune.go +++ b/rune.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:11.55085 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:43.637876 +0000 UTC package optional diff --git a/string.go b/string.go index 08d0b6a..4c04341 100644 --- a/string.go +++ b/string.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:11.941038 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:44.022296 +0000 UTC package optional diff --git a/uint.go b/uint.go index a8e8898..2093dfa 100644 --- a/uint.go +++ b/uint.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:12.325449 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:44.406039 +0000 UTC package optional diff --git a/uint16.go b/uint16.go index 641d1b1..fd0726e 100644 --- a/uint16.go +++ b/uint16.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:12.71755 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:44.798325 +0000 UTC package optional diff --git a/uint32.go b/uint32.go index ae79342..8f43dd3 100644 --- a/uint32.go +++ b/uint32.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:13.10178 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:45.183474 +0000 UTC package optional diff --git a/uint64.go b/uint64.go index f3bb1c3..a25012d 100644 --- a/uint64.go +++ b/uint64.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:13.48401 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:45.675831 +0000 UTC package optional diff --git a/uint8.go b/uint8.go index 2fbb332..ed1cd24 100644 --- a/uint8.go +++ b/uint8.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:13.907475 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:46.066068 +0000 UTC package optional diff --git a/uintptr.go b/uintptr.go index 1b734cd..1828213 100644 --- a/uintptr.go +++ b/uintptr.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2021-05-03 20:21:14.289427 +0000 UTC +// This file was generated by robots at 2021-05-03 20:24:46.705499 +0000 UTC package optional From 96a8f4e9585cafd91170d01192b20f40a2146947 Mon Sep 17 00:00:00 2001 From: Mark Phelps Date: Mon, 3 May 2021 16:27:00 -0400 Subject: [PATCH 3/3] Rm travis --- .travis.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a45dba9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: go -go: - - "1.12.x" - - "1.13.x" - -go_import_path: github.com/markphelps/optional - -cache: - directories: - - $HOME/.cache/go-build - - $GOPATH/pkg/mod - -env: - - GO111MODULE=on - -before_script: make setup -script: make ci - -notifications: - email: false