Created
September 4, 2015 05:05
-
-
Save IndianGuru/df49fe1dad787a5058d9 to your computer and use it in GitHub Desktop.
person.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In lines 31 and 37 return statement not needed, because log.Fatal calls os.Exit