GenerateUUID zum erstellen einer pseudozufälligen, 8 Stellen langen Hexadezimalzahl
This commit is contained in:
		| @@ -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)) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user