-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
48 lines (38 loc) · 911 Bytes
/
handler.go
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
package main
import (
"archive/zip"
"net/http"
"github.com/go-chi/chi"
"go.tmthrgd.dev/booked/messages"
"go.tmthrgd.dev/booked/web"
)
func open(files ...string) (http.Handler, error) {
var rcs []*zip.ReadCloser
for _, file := range files {
rc, err := zip.OpenReader(file)
if err != nil {
return nil, err
}
rcs = append(rcs, rc)
for _, f := range rc.File {
switch {
case messages.IsMessageJSON(f):
if err := messages.ParseMessageJSON(f); err != nil {
return nil, err
}
}
}
}
r := chi.NewRouter()
r.NotFound(web.NotFoundHandler())
r.MethodNotAllowed(web.MethodNotAllowedHandler())
web.MountAssets(r)
web.MountData(r, rcs...)
messages.Mount(r)
if err := messages.FixupURIs(rcs...); err != nil {
return nil, err
}
// TODO(tmthrgd): Index page.
r.Get("/", http.RedirectHandler("/messages/", http.StatusTemporaryRedirect).ServeHTTP)
return r, nil
}