mirror of
https://github.com/pcvolkmer/idicon.git
synced 2025-07-02 11:52:54 +00:00
Add web frontend
This commit is contained in:
11
idicon.go
11
idicon.go
@ -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))
|
||||
|
Reference in New Issue
Block a user