diff options
author | xengineering <me@xengineering.eu> | 2024-11-06 21:11:36 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-11-06 21:11:36 +0100 |
commit | 80107d26ef0278c5102a6f1caf4809f64c48253b (patch) | |
tree | c184f5d7d7f1ad9a766d72cc1f0d96c595aee34c | |
parent | 96cabfe72a3119f65a0d8dfc68e412c2c86dca88 (diff) | |
download | ceres-exchange-format.tar ceres-exchange-format.tar.zst ceres-exchange-format.zip |
REMOVE ME: playground: Adopt Optional for all membersexchange-format
-rw-r--r-- | playground/main.go | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/playground/main.go b/playground/main.go index 8487c5b..a4d1f81 100644 --- a/playground/main.go +++ b/playground/main.go @@ -44,22 +44,18 @@ func (o Optional[T]) MarshalJSON() ([]byte, error) { } type Testy struct { - Flag *bool `json:"flag"` - Cake *[]string `json:"cake"` + Flag Optional[bool] `json:"flag"` + Cake Optional[[]int] `json:"cake"` Opt Optional[string] `json:"opt"` } const TEXT = `{ - "cake": [ - "one", - "two", - "three" - ], - "opt": "peter" + "cake": [], + "opt": null }` -const TEMPLATE = `Flag is: {{if .Flag}}{{.Flag}}{{else}}[none]{{end}} -Cake is: {{if .Cake}}{{range .Cake}}{{.}} {{end}}{{else}}[none]{{end}} +const TEMPLATE = `Flag is: {{if .Flag.Exists}}{{.Flag.Value}}{{else}}[none]{{end}} +Cake is: {{if .Cake.Exists}}{{range .Cake.Value}}{{.}} {{end}}{{else}}[none]{{end}} Opt is: {{if .Opt.Exists}}{{.Opt.Value}}{{else}}[none]{{end}} ` |