-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
77 lines (61 loc) · 1.41 KB
/
web.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"encoding/base64"
"fmt"
"net/http"
"text/template"
"embed"
"github.com/go-chi/chi/v5"
)
//go:embed templates
var content embed.FS
func indexPage(w http.ResponseWriter, r *http.Request) {
list_tpl_text, err := content.ReadFile("templates/list.html")
entries := GroupMain()
type Zzz struct {
Entries []LogEntry
}
zzz := Zzz{Entries: entries}
if err != nil {
fmt.Println(err)
}
list_tpl, err := template.New("list").Parse(string(list_tpl_text))
if err != nil {
fmt.Println(err)
}
err = list_tpl.Execute(w, zzz)
if err != nil {
fmt.Println(err)
}
}
func issuePage(w http.ResponseWriter, r *http.Request) {
msg := chi.URLParam(r, "msg")
// base64 decode
msg_bytes, err := base64.StdEncoding.DecodeString(msg)
list_tpl_text, err := content.ReadFile("templates/show.html")
entries := aggregateIdenticalMessages(string(msg_bytes), 24)
type Zzy struct {
Entry LogEntry
Message string
}
zzz := Zzy{Entry: entries, Message: string(msg_bytes)}
if err != nil {
fmt.Println(err)
}
list_tpl, err := template.New("show").Parse(string(list_tpl_text))
if err != nil {
fmt.Println(err)
}
err = list_tpl.Execute(w, zzz)
if err != nil {
fmt.Println(err)
}
}
func testPage(w http.ResponseWriter, r *http.Request) {
contents, err := content.ReadFile("templates/test.html")
// static file no templateig needed
if err != nil {
fmt.Println(err)
}
w.Write(contents)
}