Skip to content

Instantly share code, notes, and snippets.

@prasmussen
Created June 7, 2012 17:34
Show Gist options
  • Save prasmussen/2890229 to your computer and use it in GitHub Desktop.
Save prasmussen/2890229 to your computer and use it in GitHub Desktop.
go-template-example
package main
import (
"fmt"
"bytes"
"text/template"
)
type Person struct {
Name string
}
func render(s string, i interface{}) string {
t, err := template.New("person").Parse(s)
if err != nil {
fmt.Println(err)
return ""
}
var buf bytes.Buffer
t.Execute(&buf, i)
return buf.String()
}
func main() {
s := render("Hello {{.Name}}!", &Person{Name: "Petter"})
fmt.Println(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment