I'm using Golang template package to create a templating and fills the values using struct.
Let's use the example code which can be found on the doc
type Inventory struct {
Material string
Count uint
}
sweaters := Inventory{"wool", 17}
tmpl, err := template.New("test").Parse("{{.Count}} items are made of {{.Material}}")
if err != nil { panic(err) }
err = tmpl.Execute(os.Stdout, sweaters)
if err != nil { panic(err) }
This is my situation. I received a JSON request from client with the data of the value to fill into the template. Now, this is what I wanna validate. I wanna make sure that the client sends the correct request and that each field in the struct matches with the variable on the template. Like, I wanna make sure that the struct Inventory has Count and Material.
I'm gonna validate it after the request is bind into the struct.
But, there's another thing. I have a bunch of templates. And each template has different fields and variables. So I wanna get the variable definition in the template (like {{.Count}}, counts it, and compares it to the struct.
Is there a way to do this?