Skip to content

Instantly share code, notes, and snippets.

@IndianGuru
Created September 4, 2015 05:19
Show Gist options
  • Select an option

  • Save IndianGuru/ef100313c928e0d8cd9d to your computer and use it in GitHub Desktop.

Select an option

Save IndianGuru/ef100313c928e0d8cd9d to your computer and use it in GitHub Desktop.
new_person.go
package main
import (
"log"
"os"
"text/template"
)
type Person struct {
Name string
Emails []string
}
const tmpl = `{{$name := .Name}}
{{range .Emails}}
Name is {{$name}}, email is {{.}}
{{end}}
`
func main() {
person := Person{
Name: "Satish",
Emails: []string{"[email protected]", "[email protected]"},
}
t := template.New("Person template")
t, err := t.Parse(tmpl)
if err != nil {
log.Fatal("Parse: ", err)
return
}
err = t.Execute(os.Stdout, person)
if err != nil {
log.Fatal("Execute: ", err)
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment