So I have a service which fetches the data from db and has some filteration. for sake of simplicity I create a rest service with in memory data.
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
// User represents the user data structure
type User struct {
Name string `json:"name"`
Address string `json:"address"`
Age int `json:"age"`
Designation string `json:"designation"`
}
// Predefined user data
var users = []User{
{"John Doe", "123 Main St", 30, "Software Engineer"},
{"Jane Smith", "456 Elm St", 25, "Data Scientist"},
{"Alice Johnson", "789 Oak St", 28, "Product Manager"},
{"Bob Brown", "101 Maple St", 35, "Designer"},
{"Charlie Davis", "202 Pine St", 40, "Architect"},
{"Diana Evans", "303 Cedar St", 32, "HR Manager"},
{"Evan Foster", "404 Birch St", 29, "Marketing Specialist"},
{"Fiona Green", "505 Walnut St", 27, "Sales Manager"},
{"George Harris", "606 Chestnut St", 33, "Business Analyst"},
{"Hannah White", "707 Spruce St", 31, "Operations Manager"},
}
func main() {
router := gin.Default()
// GET endpoint to fetch user data
router.GET("/users1", func(c *gin.Context) {
c.JSON(http.StatusOK, users)
})
// POST endpoint to add new user data
router.POST("/users", func(c *gin.Context) {
var newUser User
if err := c.ShouldBindJSON(&newUser); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
users = append(users, newUser)
c.JSON(http.StatusOK, newUser)
})
router.Run(":8082")
}
Issue: The doc says to compile the main.go file to main.exe first using:
CompileDaemon -command="C:\GoProject\clip\main.exe"
Then run : CompileDaemon -command=".\main.exe"
But I want my program to pick the changes as soon as I make the hnages, I dont want to re-compile my code again and again manually.
1