Advertisement
krovn

Untitled

Nov 15th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.55 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "html/template"
  5.     "net/http"
  6. )
  7.  
  8. var tpl *template.Template
  9.  
  10. func init() {
  11.     tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
  12. }
  13.  
  14. func main() {
  15.     http.HandleFunc("/", index)
  16.     http.ListenAndServe(":8080", nil)
  17. }
  18.  
  19. func index(res http.ResponseWriter, req *http.Request) {
  20.     names := []string{"janis", "kristaps", "kaspars"}
  21.     tpl.ExecuteTemplate(res, "two.gohtml", names)
  22. }
  23.  
  24. <body>
  25.     Home of two.gohtml<br />
  26.     {{range $index, $element := .}}
  27.         <li>{{$index}} - {{$element}}</li>
  28.     {{end}}
  29. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement