Created
September 4, 2015 04:56
-
-
Save IndianGuru/2591385fdc11aa248c05 to your computer and use it in GitHub Desktop.
stud_struct.go
This file contains hidden or 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 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