Skip to content

Instantly share code, notes, and snippets.

@jyap808
Created January 5, 2014 07:59
Show Gist options
  • Save jyap808/8265645 to your computer and use it in GitHub Desktop.
Save jyap808/8265645 to your computer and use it in GitHub Desktop.
Example of using the "text/template" module
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