GenerateUUID zum erstellen einer pseudozufälligen, 8 Stellen langen Hexadezimalzahl

This commit is contained in:
Jason Streifling 2023-10-10 19:06:02 +02:00
parent 2beb90a345
commit 7c7cb5959d

View File

@ -1,6 +1,8 @@
package server package server
import ( import (
"crypto/rand"
"encoding/hex"
"fmt" "fmt"
"html/template" "html/template"
"log" "log"
@ -71,6 +73,19 @@ func SubmitForm(db *db.DB, i, j *int64) http.HandlerFunc {
if err != nil { if err != nil {
_ = fmt.Errorf("SubmitForm: db.ReadAll(): %v\n", err) _ = 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))
} }
} }