/
main.go
36 lines (30 loc) · 879 Bytes
/
main.go
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
package main
import (
"fmt"
"html/template"
"log"
"net/http"
)
const PORT = ":8080"
type Page struct {
Title string
}
func indexHandler(w http.ResponseWriter, r *http.Request) {
p := &Page{Title: "Developers Stash Dashboard"}
t, _ := template.ParseFiles("templates/base.thtml", "templates/stash.thtml")
t.Execute(w, p)
}
func doNotCache(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Add("Pragma", "no-cache")
w.Header().Add("Expires", "0")
h.ServeHTTP(w, r)
})
}
func main() {
fmt.Printf("started up!\nhttp://localhost%s/\n", PORT)
http.Handle("/assets/", doNotCache(http.StripPrefix("/assets", http.FileServer(http.Dir("assets")))))
http.HandleFunc("/", indexHandler)
log.Fatal(http.ListenAndServe(PORT, nil))
}