diff options
author | Saumit Dinesan <justsaumit@protonmail.com> | 2023-09-05 11:34:21 +0530 |
---|---|---|
committer | Saumit Dinesan <justsaumit@protonmail.com> | 2023-09-05 11:34:21 +0530 |
commit | 3833e32b70f10e54bba47c89f4aea78e828ea5b0 (patch) | |
tree | 83673ebbb155a5bdb9c7ccbec9b88d5b3846e7af /server.go | |
parent | 1b9421884f3d403e3406e61cee742bd03d3a0fa5 (diff) |
Adding Blake2 Hashing with /hasher endpoint
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -7,6 +7,7 @@ import ( "fmt" "github.com/justsaumit/go-fic-api/idgen" + "github.com/justsaumit/go-fic-api/hasher" ) type HelloWorld struct { @@ -19,6 +20,10 @@ func main() { e.GET("/hello/:name", GreetingsWithParams) e.GET("/hello-queries", GreetingsWithQuery) e.GET("/genid", GenerateIDHandler) + e.GET("/hasher", hasherHandler) + e.GET("/", func(c echo.Context) error { + return c.String(http.StatusOK, "Hello, World!") + }) e.Logger.Fatal(e.Start(":3000")) } @@ -42,7 +47,6 @@ func GreetingsWithQuery(c echo.Context) error { }) } - func GenerateIDHandler(c echo.Context) error { id := idgen.GenerateID() //Print the generated ID to the console. @@ -52,3 +56,12 @@ func GenerateIDHandler(c echo.Context) error { // Message: "Generated ID: " + id, //}) } + +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)) +} |