feat: separate irc page
This commit is contained in:
parent
227226b291
commit
7f05221b1b
4 changed files with 54 additions and 4 deletions
16
main.go
16
main.go
|
|
@ -32,14 +32,26 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
ircHTML, err := fs.ReadFile(static, "irc.html")
|
||||
if err != nil {
|
||||
slog.Error("read irc", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
pages := map[string][]byte{
|
||||
"/": indexHTML,
|
||||
"/irc": ircHTML,
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
page, ok := pages[r.URL.Path]
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
uptime := uptimeLine()
|
||||
body := strings.ReplaceAll(string(indexHTML), "{{uptime}}", html.EscapeString(uptime))
|
||||
body := strings.ReplaceAll(string(page), "{{uptime}}", html.EscapeString(uptime))
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
_, _ = w.Write([]byte(body))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue