So in my main.go
I have a struct and a method that I can call from inside main.go
without a problem. Imagine it being like this:
type Test struct {
val1 float32
val2 float32
}
func (t Test) callMethod() float32 {
return t.val1 / t.val2
}
I am calling the template like this and as data I am giving an array of the Test
structs, like this:
var testvar1 Test
var testvar2 Test
var teststructs [] Test
teststructs = append(teststructs, testvar1)
teststructs = append(teststructs, testvar2)
tpl.ExecuteTemplate(w, "testpage.gohtml", teststructs)
Inside the template I am trying to call the callMethod
like this
{{range .}}
{{ .callMethod }}
{{end}}
But I am getting the following error:
executing "testpage.gohtml" at <.callMethod>: can't evaluate field callMethod in type main.Test
Has anyone an Idea what I am doing wrong and has a solution for this? I am trying to fix it since many hours and I am so frustrated at this point.