Skip to content

Instantly share code, notes, and snippets.

@IndianGuru
Created September 4, 2015 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndianGuru/df49fe1dad787a5058d9 to your computer and use it in GitHub Desktop.
Save IndianGuru/df49fe1dad787a5058d9 to your computer and use it in GitHub Desktop.
person.go
package main
import (
"log"
"os"
"text/template"
)
type Person struct {
Name string
Emails []string
}
const tmpl = `The name is {{.Name}}.
{{range .Emails}}
His email id is {{.}}
{{end}}
`
func main() {
person := Person{
Name: "Satish",
Emails: []string{"satish@rubylearning.org", "satishtalim@gmail.com"},
}
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
}
}
@dchebakov
Copy link

In lines 31 and 37 return statement not needed, because log.Fatal calls os.Exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment