Advertisement
krovn

Untitled

Nov 15th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.59 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.     mappy := map[int]string{
  21.         1: "viens",
  22.         2: "divi",
  23.         3: "tris",
  24.         4: "cetri",
  25.     }
  26.     tpl.ExecuteTemplate(res, "two.gohtml", mappy)
  27. }
  28.  
  29.  
  30.  
  31. <body>
  32.     Home of two.gohtml<br />
  33.     {{range $cipars,$vards := .}}
  34.         <li>{{$cipars}} ir "{{$vards}}"</li>
  35.     {{end}}
  36. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement