summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-09-04 16:19:32 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-09-04 16:19:32 +0530
commit117d461c4944f189576f0c4967851de458ba6f32 (patch)
tree7248b4bde0cf03e06920bf3622228652cc71b5ba
parent1f61825e4b0b46d65b0a379c6b87e50d1467cfdc (diff)
Updating README + Creating idgen package and importing it
-rw-r--r--README.md10
-rw-r--r--idgen/id_generator.go29
-rw-r--r--main.go15
3 files changed, 53 insertions, 1 deletions
diff --git a/README.md b/README.md
index 4ab0c58..546c993 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,6 @@
# 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, thereby providing integrity service that aligns with the CIA (Confidentiality, Integrity, Availability) triad for data security.
+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).
+Thereby providing both confidentiality and integrity service that aligns with the CIA (Confidentiality, Integrity, Availability) triad for data security.
## Getting Started
@@ -40,6 +41,13 @@ Once the server is running, you can access the API endpoints to add file hashes
- To add a file hash, make a POST request to `/add` with JSON data containing the ID and hash.
- To verify a file hash, make a POST request to `/verify` with JSON data containing the ID and hash.
+## To-Do-List
+- [x] Perform short ID Generation (API/Application)
+- [ ] Perform Hashing (API/Application)
+- [ ] Connect with DB
+- [ ] Add JSON data to DB
+- [ ] Perform verification
+
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
diff --git a/idgen/id_generator.go b/idgen/id_generator.go
new file mode 100644
index 0000000..8c34f41
--- /dev/null
+++ b/idgen/id_generator.go
@@ -0,0 +1,29 @@
+// id_generator.go
+package idgen
+
+import (
+ "math/rand"
+ "time"
+)
+
+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++ {
+ id[i] = chars[rand.Intn(len(chars))]
+ }
+ return string(id)
+}
diff --git a/main.go b/main.go
index 34df0fa..fb9628e 100644
--- a/main.go
+++ b/main.go
@@ -4,6 +4,9 @@ import (
"net/http"
"github.com/labstack/echo/v4"
+
+ "fmt"
+ "github.com/justsaumit/fis-golang/idgen"
)
type HelloWorld struct {
@@ -15,6 +18,7 @@ func main() {
e.GET("/hello", Greetings)
e.GET("/hello/:name", GreetingsWithParams)
e.GET("/hello-queries", GreetingsWithQuery)
+ e.GET("/genid", GenerateIDHandler)
e.Logger.Fatal(e.Start(":3000"))
}
@@ -37,3 +41,14 @@ func GreetingsWithQuery(c echo.Context) error {
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,
+ //})
+}