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 diff --git a/bool.go b/bool.go index fbc6f2b..1c93937 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:24:37.859274 +0000 UTC package optional diff --git a/byte.go b/byte.go index 39409d8..c9335a4 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:24:38.247279 +0000 UTC package optional diff --git a/cmd/optional/main.go b/cmd/optional/main.go index 0c8ce56..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" ) @@ -179,6 +181,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 +206,5 @@ func ({{ .VariableName }} *{{ .OutputName }}) UnmarshalJSON(data []byte) error { {{ .VariableName }}.value = &value return nil } +{{- end }} ` 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 b85dfbe..2200dc9 100644 --- a/complex128.go +++ b/complex128.go @@ -1,10 +1,9 @@ // 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:24:38.633502 +0000 UTC package optional import ( - "encoding/json" "errors" ) @@ -51,27 +50,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..9d07d4a 100644 --- a/complex64.go +++ b/complex64.go @@ -1,10 +1,9 @@ // 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:24:39.017904 +0000 UTC package optional import ( - "encoding/json" "errors" ) @@ -51,27 +50,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..ff6c62e 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:24:39.403027 +0000 UTC package optional diff --git a/float32.go b/float32.go index 9f42c2c..bdff83b 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:24:39.935633 +0000 UTC package optional diff --git a/float64.go b/float64.go index 15966b6..640cbe8 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:24:41.277145 +0000 UTC package optional diff --git a/int.go b/int.go index caead99..bf9fcae 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:24:41.676284 +0000 UTC package optional diff --git a/int16.go b/int16.go index 9532996..37ab9c0 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:24:42.065863 +0000 UTC package optional diff --git a/int32.go b/int32.go index 07c212d..8dd9690 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:24:42.453259 +0000 UTC package optional diff --git a/int64.go b/int64.go index 7f8f01c..dbfd972 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:24:42.850127 +0000 UTC package optional diff --git a/int8.go b/int8.go index 182f814..f63b049 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:24:43.246461 +0000 UTC package optional diff --git a/rune.go b/rune.go index 469de67..bc5e8cc 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:24:43.637876 +0000 UTC package optional diff --git a/string.go b/string.go index 19e67c1..4c04341 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:24:44.022296 +0000 UTC package optional diff --git a/uint.go b/uint.go index 33e93e3..2093dfa 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:24:44.406039 +0000 UTC package optional diff --git a/uint16.go b/uint16.go index 428ecbf..fd0726e 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:24:44.798325 +0000 UTC package optional diff --git a/uint32.go b/uint32.go index 5fa2ebf..8f43dd3 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:24:45.183474 +0000 UTC package optional diff --git a/uint64.go b/uint64.go index f0d79a4..a25012d 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:24:45.675831 +0000 UTC package optional diff --git a/uint8.go b/uint8.go index 9b2be7f..ed1cd24 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:24:46.066068 +0000 UTC package optional diff --git a/uintptr.go b/uintptr.go index af79fef..1828213 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:24:46.705499 +0000 UTC package optional