From 1b9421884f3d403e3406e61cee742bd03d3a0fa5 Mon Sep 17 00:00:00 2001
From: Saumit Dinesan <justsaumit@protonmail.com>
Date: Mon, 4 Sep 2023 19:05:57 +0530
Subject: Refactoring code

---
 README.md             | 10 +++++-----
 go.mod                |  2 +-
 idgen/id_generator.go |  5 -----
 main.go               | 54 ---------------------------------------------------
 server.go             | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 60 insertions(+), 65 deletions(-)
 delete mode 100644 main.go
 create mode 100644 server.go

diff --git a/README.md b/README.md
index 546c993..4d335e5 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-# Golang Backend API using Echo for FSI(File System Integrity) Application
-Developing a simple Golang backend API using the [Echo framework](https://github.com/labstack/echo). This API stores IDs and their corresponding hashes in a SQL server and provides functionality to verify if a given hash matches the stored hash for a specific ID. All the communication between the Application and API will secured using TLS encryption(HTTPS).  
+# Golang Backend API for FIC (File Integrity Checker) Application
+Developing a simple Golang backend API with the [Echo framework](https://github.com/labstack/echo) for FIC(File Integrity Checker) application. This API stores IDs and their corresponding hashes in a SQL server and provides functionality to verify if a given hash matches the stored hash for a specific ID. All the communication between the Application and API is secured using TLS encryption(HTTPS).  
 Thereby providing both confidentiality and integrity service that aligns with the CIA (Confidentiality, Integrity, Availability) triad for data security.
 
 ## Getting Started
@@ -16,8 +16,8 @@ To get started with this project, follow these steps:
 1. Clone this repository to your local machine:
 
   ```bash
-  git clone https://github.com/justsaumit/go-fsi-api.git
-  cd go-fsi-api
+  git clone https://github.com/justsaumit/go-fic-api.git
+  cd go-fic-api
   ```
 
 2. Initialize and install project dependencies using Go modules:
@@ -31,7 +31,7 @@ To get started with this project, follow these steps:
 4. Run the server:
 
   ```bash
-  go run main.go
+  go run server.go
   ```
 
 ### Usage
diff --git a/go.mod b/go.mod
index 7d3f82d..a0fd901 100644
--- a/go.mod
+++ b/go.mod
@@ -1,4 +1,4 @@
-module github.com/justsaumit/fis-golang
+module github.com/justsaumit/go-fic-api
 
 go 1.21.0
 
diff --git a/idgen/id_generator.go b/idgen/id_generator.go
index 8c34f41..3659d0e 100644
--- a/idgen/id_generator.go
+++ b/idgen/id_generator.go
@@ -1,4 +1,3 @@
-// id_generator.go
 package idgen
 
 import (
@@ -7,19 +6,15 @@ import (
 )
 
 const (
-	// Define the character set for the generated IDs.
 	chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
 
-	// Define the desired length of the generated IDs.
 	idLength = 8
 )
 
-// Initialize the random number generator.
 func init() {
 	rand.Seed(time.Now().UnixNano())
 }
 
-// GenerateID generates a short and readable ID.
 func GenerateID() string {
 	id := make([]byte, idLength)
 	for i := 0; i < idLength; i++ {
diff --git a/main.go b/main.go
deleted file mode 100644
index fb9628e..0000000
--- a/main.go
+++ /dev/null
@@ -1,54 +0,0 @@
-package main
-
-import (
-  "net/http"
-
-  "github.com/labstack/echo/v4"
-
-  "fmt"
-  "github.com/justsaumit/fis-golang/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.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,
-    //})
-}
diff --git a/server.go b/server.go
new file mode 100644
index 0000000..d610b92
--- /dev/null
+++ b/server.go
@@ -0,0 +1,54 @@
+package main
+
+import (
+  "net/http"
+
+  "github.com/labstack/echo/v4"
+
+  "fmt"
+  "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.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,
+    //})
+}
-- 
cgit v1.2.3