Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "html/template"
- "net/http"
- )
- type person struct {
- Name string
- Age int
- }
- var tpl *template.Template
- func init() {
- tpl = template.Must(template.ParseFiles("templates/two.gohtml"))
- }
- func (p person) AgeDbl() int {
- return p.Age * 2
- }
- func (p person) Dbl(x int) int {
- return x * 2
- }
- func main() {
- http.HandleFunc("/", index)
- http.ListenAndServe(":8080", nil)
- }
- func index(res http.ResponseWriter, req *http.Request) {
- p := person{
- Name: "Janis",
- Age: 24,
- }
- tpl.ExecuteTemplate(res, "two.gohtml", p)
- }
- /*
- <body>
- This might be two.gohtml? But I am not sure.
- <h3>
- {{.Age}}|{{.Name}}|{{.AgeDbl}}|{{.AgeDbl|.Dbl}}
- </h3>
- </body>
- This might be two.gohtml? But I am not sure.
- 24|Janis|48|96
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement