From 5befff0716d7f7342854c04e05c1003babf5a646 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Mon, 20 May 2024 12:49:36 +0200 Subject: [PATCH] Add web frontend --- LICENSE | 2 +- idicon.go | 11 ++ static/index.html | 264 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 static/index.html diff --git a/LICENSE b/LICENSE index 4818d1a..5b29161 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2021 Paul-Christian Volkmer +Copyright (c) 2024 Paul-Christian Volkmer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/idicon.go b/idicon.go index d2f84e9..b6d60ed 100644 --- a/idicon.go +++ b/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)) diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..0a7eb3e --- /dev/null +++ b/static/index.html @@ -0,0 +1,264 @@ + + + + + Idicon + + + +
+

Generate an identicon

+ +
+ +
+
+ +
+
+ Settings +
+ + +
+
+ + +
+
+ + +
+
+
+ Actions + +
+
+
+ + + + \ No newline at end of file