Skip to content

Instantly share code, notes, and snippets.

@IndianGuru
Created September 4, 2015 04:56
Show Gist options
  • Select an option

  • Save IndianGuru/2591385fdc11aa248c05 to your computer and use it in GitHub Desktop.

Select an option

Save IndianGuru/2591385fdc11aa248c05 to your computer and use it in GitHub Desktop.
stud_struct.go
package main
import (
"log"
"os"
"text/template"
)
type Student struct {
//exported field since it begins
//with a capital letter
Name string
}
func main() {
//define an instance
s := Student{"Satish"}
//create a new template with some name
tmpl := template.New("test")
//parse some content and generate a template
tmpl, err := tmpl.Parse("Hello {{.Name}}!")
if err != nil {
log.Fatal("Parse: ", err)
return
}
//merge template 'tmpl' with content of 's'
err1 := tmpl.Execute(os.Stdout, s)
if err1 != nil {
log.Fatal("Execute: ", err1)
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment