diff options
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | idgen/id_generator.go | 29 | ||||
-rw-r--r-- | main.go | 15 |
3 files changed, 53 insertions, 1 deletions
@@ -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) +} @@ -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, + //}) +} |