-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.go
More file actions
28 lines (24 loc) · 655 Bytes
/
Copy pathui.go
File metadata and controls
28 lines (24 loc) · 655 Bytes
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
package main
import (
"embed"
"io/fs"
"net/http"
"strings"
)
//go:embed web
var webFiles embed.FS
func registerUI(mux *http.ServeMux, api *API) {
staticFS, err := fs.Sub(webFiles, "web/static")
if err == nil {
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticFS))))
}
mux.HandleFunc("GET /", api.index)
}
func (a *API) index(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" && r.URL.Path != "/ui" && !strings.HasPrefix(r.URL.Path, "/ui/") {
http.NotFound(w, r)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
http.ServeFileFS(w, r, webFiles, "web/index.html")
}