I am trying to convert a golang template, and allow ignoring if the match is not found. Is that possible?
package main
import (
"bytes"
"fmt"
"text/template"
)
type Person struct {
Name string
Age int
}
type Info struct {
Name string
Id int
}
func main() {
msg := "Hello {{ .Id }} With name {{ .Name }}"
p := Person{Name: "John", Age: 24}
i := Info{Name: "none", Id: 5}
t := template.New("My template")
t, _ = t.Parse(msg)
buf := new(bytes.Buffer)
t.Execute(buf, p)
fmt.Println(buf.String())
buf = new(bytes.Buffer)
t.Execute(buf, i)
fmt.Println(buf.String())
}
I would like this to print
Hello {{ .Id }} with name John
Hello 5 With name none