summaryrefslogtreecommitdiff
path: root/internal/adminui/ui.go
blob: 49899ea687565275ed977c8954997615c36c0e12 (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
package adminui

import (
	"embed"
	"io/fs"
	"net/http"
)

//go:embed assets/*
var assets embed.FS

func Handler() http.Handler {
	content, err := fs.Sub(assets, "assets")
	if err != nil {
		panic(err)
	}
	files := http.FileServer(http.FS(content))
	mux := http.NewServeMux()
	mux.HandleFunc("GET /models", func(w http.ResponseWriter, r *http.Request) {
		http.ServeFileFS(w, r, content, "models.html")
	})
	mux.HandleFunc("GET /models/", func(w http.ResponseWriter, r *http.Request) {
		http.Redirect(w, r, "../models", http.StatusPermanentRedirect)
	})
	mux.Handle("/", files)
	return mux
}