Created
March 31, 2021 06:41
-
-
Save krishbhanushali/ab459c4020b2066b39d5cf02608e41eb to your computer and use it in GitHub Desktop.
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 ( | |
"log" | |
"os" | |
"text/template" | |
) | |
type Person struct { | |
FirstName string | |
LastName string | |
EmailAddress string | |
PhoneNumber string | |
} | |
func main() { | |
const sample = `{{range .}} | |
Name: {{- .FirstName}} {{.LastName}} | |
Email Address: {{- .EmailAddress}} | |
Phone Number: {{- .PhoneNumber}} | |
{{end}} | |
` | |
persons := []Person{ | |
{ | |
FirstName: "John", | |
LastName: "Doe", | |
EmailAddress: "[email protected]", | |
PhoneNumber: "+19876543210", | |
}, | |
{ | |
FirstName: "Fredrika", | |
LastName: "Gaila", | |
EmailAddress: "[email protected]", | |
PhoneNumber: "+11234567890", | |
}, | |
} | |
t := template.Must(template.New("sampleTest").Parse(sample)) | |
err := t.Execute(os.Stdout, persons) | |
if err != nil { | |
log.Println(err.Error()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment