summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-11-04 21:40:26 +0100
committerxengineering <me@xengineering.eu>2024-11-04 21:40:26 +0100
commitb8999e29ab99073ccdc1d83c3ec57fd2350684b5 (patch)
treeae32f1508b0fca6a80e0f2872aac423f90f8acda
parent99cff9a3102c64cd146d524524001bd6ecb246c4 (diff)
downloadceres-b8999e29ab99073ccdc1d83c3ec57fd2350684b5.tar
ceres-b8999e29ab99073ccdc1d83c3ec57fd2350684b5.tar.zst
ceres-b8999e29ab99073ccdc1d83c3ec57fd2350684b5.zip
REMOVE ME: Add debug file to test optional struct members
-rw-r--r--playground/main.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/playground/main.go b/playground/main.go
new file mode 100644
index 0000000..38b5f0d
--- /dev/null
+++ b/playground/main.go
@@ -0,0 +1,45 @@
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "html/template"
+ "log"
+ "os"
+)
+
+type Testy struct {
+ Flag *bool `json:"flag"`
+ Cake *[]string `json:"cake"`
+}
+
+const TEXT = `{
+ "cake": [
+ "one",
+ "two",
+ "three"
+ ]
+}`
+
+const TEMPLATE = `Flag is: {{if .Flag}}{{.Flag}}{{else}}[none]{{end}}
+Cake is: {{if .Cake}}{{range .Cake}}{{.}} {{end}}{{else}}[none]{{end}}
+`
+
+func main() {
+ var t Testy
+ json.Unmarshal([]byte(TEXT), &t)
+
+ tmpl, err := template.New("mytemplate").Parse(TEMPLATE)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ tmpl.Execute(os.Stdout, t)
+
+ b, err := json.Marshal(t)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ fmt.Println(string(b))
+}