I have the following code which generates the following output
code:
package main
import (
"html/template"
"os"
)
type EntetiesClass struct {
Name string
Value int32
}
// In the template, we use rangeStruct to turn our struct values
// into a slice we can iterate over
var htmlTemplate = `{{range $index, $element := .}}
{{range $element}}{{.Name}}={{.Value}}
{{- end}}
{{- end}}`
func main() {
data := map[string][]EntetiesClass{
"Container1": {{"Test", 15}},
"Container2": {{"Test", 15}},
}
t := template.New("t")
t, err := t.Parse(htmlTemplate)
if err != nil {
panic(err)
}
err = t.Execute(os.Stdout, data)
if err != nil {
panic(err)
}
}
link: https://play.golang.org/p/yM9_wWmyLY
Output:
Test=15 Test=15
I want to compare the Container1 with Container2 and if they have common key, i just want to print output only once.
Output: Test=15
How can i achieve this? Any help is appreciated?