summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-11-28 15:17:18 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-11-28 15:17:18 +0530
commit82d5136c1b03efbb99931884dd75ab1160689ceb (patch)
tree3095f344055c4ad54a8238599839fa0088054fbd /server.go
parenta3ead3d67520704eda55a74841b00d5766728fab (diff)
Refactoring project - Introducing handlers,models and utils- Updating previous hasher and idgen func + formatting
Diffstat (limited to 'server.go')
-rw-r--r--server.go77
1 files changed, 4 insertions, 73 deletions
diff --git a/server.go b/server.go
index defa8c1..1d73a0f 100644
--- a/server.go
+++ b/server.go
@@ -1,82 +1,13 @@
package main
import (
- "net/http"
-
+ "github.com/justsaumit/go-fis-api/handlers"
"github.com/labstack/echo/v4"
-
- "fmt"
- "github.com/justsaumit/go-fic-api/hasher"
- "github.com/justsaumit/go-fic-api/idgen"
)
-type HelloWorld struct {
- Message string `json:"message"`
-}
-
func main() {
e := echo.New()
- e.GET("/hello", Greetings)
- 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"))
-}
-
-func Greetings(c echo.Context) error {
- return c.JSON(http.StatusOK, HelloWorld{
- Message: "Hello World",
- })
-}
-
-func GreetingsWithParams(c echo.Context) error {
- params := c.Param("name")
- return c.JSON(http.StatusOK, HelloWorld{
- Message: "Hello World, my name is " + params,
- })
-}
-
-func GreetingsWithQuery(c echo.Context) error {
- query := c.QueryParam("name")
- return c.JSON(http.StatusOK, HelloWorld{
- Message: "Hello World, I'm using queries and my name is " + query,
- })
-}
-
-func GenerateIDHandler(c echo.Context) error {
- id := idgen.GenerateID()
- //Print the generated ID to the console.
- fmt.Println("Generated ID:", id)
- return c.JSON(http.StatusOK, map[string]string{"message": "Generated ID: " + id})
- // return c.JSON(http.StatusOK, HelloWorld{
- // Message: "Generated ID: " + id,
- //})
-}
-
-func hasherHandler(c echo.Context) error {
- 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)
+ e.POST("/upload", handlers.AddHash)
+ //e.POST("/verify", handlers.VerifyHash)
+ e.Logger.Fatal(e.StartTLS(":3000", "/etc/letsencrypt/live/draconyan.xyz/fullchain.pem", "/etc/letsencrypt/live/draconyan.xyz/privkey.pem"))
}