blob: 98216728f8ce2ff7a85318166fd7e9897ad32ddc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package main
import (
"fmt"
"log"
"net/http"
"text/template"
)
type Server struct {
template *template.Template
}
func (c *Server) rootHandle(w http.ResponseWriter, r * http.Request) {
tmpl, err := template.ParseFiles("templates/index.html")
if err != nil {
log.Println(err)
return
}
tmpl.Execute(w, nil)
}
func main() {
fmt.Println("Hello world!")
template, err := template.ParseFS(templates, "templates/*.html")
if err != nil {
log.Fatal(err)
}
s := Server {
template: template,
}
http.HandleFunc("/", s.rootHandle)
log.Fatal(http.ListenAndServe(":8080", nil))
}
|