-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathui.go
More file actions
51 lines (39 loc) · 1003 Bytes
/
Copy pathui.go
File metadata and controls
51 lines (39 loc) · 1003 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
_ "embed"
"net/http"
"github.com/go-chi/chi/v5"
)
//go:embed ui/index.html
var index []byte
//go:embed ui/css/vendor.css
var vendor []byte
//go:embed ui/css/style.css
var css []byte
//go:embed ui/js/app.js
var js []byte
type uiResource struct{}
func (rs uiResource) Routes() chi.Router {
r := chi.NewRouter()
r.Get("/", rs.Index)
r.Get("/css/vendor.css", rs.Vendor)
r.Get("/css/style.css", rs.CSS)
r.Get("/js/app.js", rs.JS)
return r
}
func (rs uiResource) Index(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
w.Write(index)
}
func (rs uiResource) Vendor(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/css")
w.Write(vendor)
}
func (rs uiResource) CSS(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/css")
w.Write(css)
}
func (rs uiResource) JS(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/javascript")
w.Write(js)
}