Hello,
I have a problem.
I try to pass a struct to a template, but the values go null
Example:
package main
import (
"fmt"
"log"
"os"
"text/template"
)
var tpl *template.Template
type values struct {
stringPagar string
stringReceber string
}
func init() {
tpl = template.Must(template.ParseFiles("tpl.gohtml"))
}
func main() {
err := os.Remove("test.txt") //delet
if err != nil {
log.Fatal(err)
}
nf, err := os.Create("test.txt")
if err != nil {
log.Fatal(err)
}
defer nf.Close()
fmt.Println("Hello")
valores := values{
stringPagar: "100,200,300",
stringReceber: "400,500,600",
}
tpl.ExecuteTemplate(nf, "tpl.gohtml", valores)
}
My tpl.gohtml:
Test
{{.stringPagar}}
Test 2
{{.stringReceber}}
Result in test.txt
Test
Can someone help me?