From 3833e32b70f10e54bba47c89f4aea78e828ea5b0 Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Tue, 5 Sep 2023 11:34:21 +0530 Subject: Adding Blake2 Hashing with /hasher endpoint --- server.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'server.go') diff --git a/server.go b/server.go index d610b92..cd2978d 100644 --- a/server.go +++ b/server.go @@ -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)) +} -- cgit v1.2.3