From 80107d26ef0278c5102a6f1caf4809f64c48253b Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 6 Nov 2024 21:11:36 +0100 Subject: REMOVE ME: playground: Adopt Optional for all members --- playground/main.go | 16 ++++++---------- 1 file 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}} ` -- cgit v1.2.3-70-g09d2