summaryrefslogtreecommitdiff
path: root/pkg/webui/index.go
blob: 11680988f56d04807bb0eaaa88503a266f970634 (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
package webui

import (
	"fmt"
	"net/http"

	"git.adyxax.org/adyxax/tfstated/pkg/model"
)

type Page struct {
	LightMode bool
	Precedent string
	Section   string
	Title     string
}

func makePage(r *http.Request, page *Page) *Page {
	settings := r.Context().Value(model.SettingsContextKey{}).(*model.Settings)
	page.LightMode = settings.LightMode
	return page
}

func handleIndexGET() http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if r.URL.Path == "/" {
			http.Redirect(w, r, "/states", http.StatusFound)
		} else {
			errorResponse(w, http.StatusNotFound, fmt.Errorf("Page not found"))
		}
	})
}