From 7c7cb5959dcb273c6f33073fbe47aea47da1073e Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Tue, 10 Oct 2023 19:06:02 +0200 Subject: [PATCH] =?UTF-8?q?GenerateUUID=20zum=20erstellen=20einer=20pseudo?= =?UTF-8?q?zuf=C3=A4lligen,=208=20Stellen=20langen=20Hexadezimalzahl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/server.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/server/server.go b/packages/server/server.go index 2f70433..10ab54a 100644 --- a/packages/server/server.go +++ b/packages/server/server.go @@ -1,6 +1,8 @@ package server import ( + "crypto/rand" + "encoding/hex" "fmt" "html/template" "log" @@ -71,6 +73,19 @@ func SubmitForm(db *db.DB, i, j *int64) http.HandlerFunc { if err != nil { _ = fmt.Errorf("SubmitForm: db.ReadAll(): %v\n", err) } - template.Must(template.ParseFiles("templates/index.html", "templates/table.html")).Execute(w, bs) + template.Must(template.ParseFiles("templates/table.html")).Execute(w, bs) + } +} + +func GenerateUUID() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + bs := make([]byte, 4) + + _, err := rand.Read(bs) + if err != nil { + _ = fmt.Errorf("GenerateUUID: rand.Read(bs): %v\n", err) + } + + template.Must(template.ParseFiles("templates/form.html")).ExecuteTemplate(w, "uuid", hex.EncodeToString(bs)) } }