diff options
author | Saumit Dinesan <justsaumit@protonmail.com> | 2023-09-05 11:48:40 +0530 |
---|---|---|
committer | Saumit Dinesan <justsaumit@protonmail.com> | 2023-09-05 11:48:40 +0530 |
commit | 48979e3f848ab0159156f87823bc8f3358925523 (patch) | |
tree | 68873e5392cb0b96b3f02851995d7e2504a77758 | |
parent | 3833e32b70f10e54bba47c89f4aea78e828ea5b0 (diff) |
Applying Blake2b Hash to multiple files
-rw-r--r-- | message-copy.txt | 1 | ||||
-rw-r--r-- | message-modd.txt | 1 | ||||
-rw-r--r-- | server.go | 27 |
3 files changed, 23 insertions, 6 deletions
diff --git a/message-copy.txt b/message-copy.txt new file mode 100644 index 0000000..43be410 --- /dev/null +++ b/message-copy.txt @@ -0,0 +1 @@ +This is a sample message. diff --git a/message-modd.txt b/message-modd.txt new file mode 100644 index 0000000..ac508a3 --- /dev/null +++ b/message-modd.txt @@ -0,0 +1 @@ +This is a modified message. @@ -58,10 +58,25 @@ func GenerateIDHandler(c echo.Context) error { } func hasherHandler(c echo.Context) error { - filePath := "./message-orig.txt" - hash, err := hasher.CalculateBLAKE2Hash(filePath) - if err != nil { - return c.String(http.StatusInternalServerError, "Error calculating hash") - } - return c.String(http.StatusOK, fmt.Sprintf("BLAKE2b hash of %s: %s\n", filePath, hash)) + filePaths := []string{ + "./message-orig.txt", + "./message-copy.txt", + "./message-modd.txt", + } + hashResults := make(map[string]string) + + for _, filePath := range filePaths { + hash, err := hasher.CalculateBLAKE2Hash(filePath) + if err != nil { + return c.String(http.StatusInternalServerError, "Error calculating hash") + } + hashResults[filePath] = hash + } + + response := "BLAKE2b hashes:\n" + for filePath, hash := range hashResults { + response += fmt.Sprintf("%s: %s\n", filePath, hash) + } + + return c.String(http.StatusOK, response) } |