From c694061e251c52c4ce7ab059f5aed41ed5838d8b Mon Sep 17 00:00:00 2001
From: Will McCutchen <will@mccutch.org>
Date: Wed, 3 Jul 2019 14:21:32 -0700
Subject: [PATCH] Panic if we can't read random data for uuid

---
 httpbin/handlers.go | 7 +------
 httpbin/helpers.go  | 7 +++----
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/httpbin/handlers.go b/httpbin/handlers.go
index e6738c6..5828599 100644
--- a/httpbin/handlers.go
+++ b/httpbin/handlers.go
@@ -898,13 +898,8 @@ func (h *HTTPBin) DigestAuth(w http.ResponseWriter, r *http.Request) {
 
 // UUID - responds with a generated UUID
 func (h *HTTPBin) UUID(w http.ResponseWriter, r *http.Request) {
-	u, err := uuidv4()
-	if err != nil {
-		http.Error(w, fmt.Sprintf("Failed to generate uuid: %s", err), http.StatusInternalServerError)
-		return
-	}
 	resp, _ := json.Marshal(&uuidResponse{
-		UUID: u,
+		UUID: uuidv4(),
 	})
 	writeJSON(w, resp, http.StatusOK)
 }
diff --git a/httpbin/helpers.go b/httpbin/helpers.go
index 87acfbb..4c4c66c 100644
--- a/httpbin/helpers.go
+++ b/httpbin/helpers.go
@@ -236,16 +236,15 @@ func sha1hash(input string) string {
 	return fmt.Sprintf("%x", h.Sum([]byte(input)))
 }
 
-func uuidv4() (string, error) {
+func uuidv4() string {
 	buff := make([]byte, 16)
 	_, err := rand.Read(buff[:])
 	if err != nil {
-		return "", err
+		panic(err)
 	}
 	buff[6] = (buff[6] & 0x0f) | 0x40 // Version 4
 	buff[8] = (buff[8] & 0x3f) | 0x80 // Variant 10
-	uuid := fmt.Sprintf("%x-%x-%x-%x-%x", buff[0:4], buff[4:6], buff[6:8], buff[8:10], buff[10:])
-	return uuid, nil
+	return fmt.Sprintf("%x-%x-%x-%x-%x", buff[0:4], buff[4:6], buff[6:8], buff[8:10], buff[10:])
 }
 
 // base64Helper - describes the base64 operation (encode|decode) and input data
-- 
GitLab