diff options
-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}} ` |