Implementing a Tree with different Types in Child Nodes (like JSON, but more strictly typed)


(Anton) #1

I have a web form that I would like to represent as a tree of various types in Go.

What’s is an effective way to implement it in the go idiomatic way?

The node types are:

  • the root (the form itself)
  • pages (in a multi-page form)
  • sections
  • concrete inputs (text input, checkbox, etc)
  • conditional fields and sections (i.e. containing a formula referencing other fields/sections; once evaluated to TRUE or FALSE, will make the field visible / not visible when the form is rendered)
  • repeatable fields (for example, when the respondent can click on the “Add City” button and enter one more city - multiple times)