Created
January 5, 2014 07:59
-
-
Save jyap808/8265645 to your computer and use it in GitHub Desktop.
Example of using the "text/template" module
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 ( | |
"os" | |
"text/template" | |
) | |
type Person struct { | |
Name string //exported field since it begins with a capital letter | |
} | |
func main() { | |
t := template.New("hello template") //create a new template with some name | |
t, _ = t.Parse("hello {{.Name}}!\n") //parse some content and generate a template, which is an internal representation | |
p := Person{Name: "Mary"} //define an instance with required field | |
t.Execute(os.Stdout, p) //merge template ‘t’ with content of ‘p’ | |
} | |
// From: http://golangtutorials.blogspot.com/2011/06/go-templates.html | |
// http://golangtutorials.blogspot.com/2011/10/go-templates-part-2.html | |
// http://golangtutorials.blogspot.com/2011/11/go-templates-part-3-template-sets.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment