Add web frontend

This commit is contained in:
2024-05-20 12:49:36 +02:00
parent 79fc47068b
commit 5befff0716
3 changed files with 276 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"embed"
"flag"
"fmt"
"github.com/BurntSushi/toml"
@ -13,6 +14,15 @@ import (
"strconv"
)
//go:embed static
var static embed.FS
func pageRequestHandler(w http.ResponseWriter, _ *http.Request) {
p, _ := static.ReadFile("static/index.html")
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = w.Write(p)
}
func requestHandler(w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
@ -106,6 +116,7 @@ func main() {
configure(*configFile)
router := mux.NewRouter()
router.HandleFunc("/avatar", pageRequestHandler)
router.HandleFunc("/avatar/{id}", requestHandler)
log.Printf("Starting on port %d ...\n", *port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), router))