page_index.go 1.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
package main

import (
	"net/http"
)

type IndexData struct {
	User UserInfo
}

func pageIndex(ctx PageContext) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.URL.Path == "/" {
			user := parseUser(r)

			if err := formatTemplate(w, "index.html", IndexData{
				user,
			}); err != nil {
				panic(err)
			}
Janne Koschinski's avatar
Janne Koschinski committed
21 22 23 24 25 26 27 28 29 30 31 32
        } else if r.URL.Path == "/favicon.ico" {
			w.Header().Set("Vary", "Accept-Encoding")
			w.Header().Set("Cache-Control", "public, max-age=31536000")
			ctx.AssetServer.ServeHTTP(w, r)
        } else if r.URL.Path == "/favicon.png" {
			w.Header().Set("Vary", "Accept-Encoding")
			w.Header().Set("Cache-Control", "public, max-age=31536000")
			ctx.AssetServer.ServeHTTP(w, r)
        } else if r.URL.Path == "/favicon.svg" {
			w.Header().Set("Vary", "Accept-Encoding")
			w.Header().Set("Cache-Control", "public, max-age=31536000")
			ctx.AssetServer.ServeHTTP(w, r)
33
		} else {
Janne Koschinski's avatar
Janne Koschinski committed
34 35
			w.Header().Set("Vary", "Accept-Encoding")
			w.Header().Set("Cache-Control", "public, max-age=31536000")
36 37 38 39
			ctx.Images.ServeHTTP(w, r)
		}
	})
}