|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"git.sp4ke.xyz/AnisB/shelf_api_go/controllers"
|
|
|
|
"git.sp4ke.xyz/AnisB/shelf_api_go/db_client"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
db_client.InitialiseDBConnection()
|
|
|
|
|
|
|
|
r := gin.Default()
|
|
|
|
|
|
|
|
r.GET("/", func(ctx *gin.Context) {
|
|
|
|
ctx.JSON(http.StatusOK, gin.H{"status": "success", "message": "Welcome to Golang with PostgreSQL"})
|
|
|
|
})
|
|
|
|
|
|
|
|
// Products
|
|
|
|
r.GET("/products", controllers.GetProducts)
|
|
|
|
r.GET("/products/:id", controllers.GetProduct)
|
|
|
|
r.POST("/products", controllers.CreateProduct)
|
|
|
|
r.PUT("/products/:id", controllers.UpdateProduct)
|
|
|
|
r.DELETE("/products/:id", controllers.DeleteProduct)
|
|
|
|
|
|
|
|
// Users
|
|
|
|
r.GET("/users", controllers.GetUsers)
|
|
|
|
r.GET("/users/:id", controllers.GetUser)
|
|
|
|
r.POST("/users", controllers.CreateUser)
|
|
|
|
r.PUT("/users/:id", controllers.UpdateUser)
|
|
|
|
r.DELETE("/users/:id", controllers.DeleteUser)
|
|
|
|
|
|
|
|
if err := r.Run(":5000"); err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
/*router := server.Group("/api")
|
|
|
|
|
|
|
|
router.GET("/healthchecker", func(ctx *gin.Context) {
|
|
|
|
ctx.JSON(http.StatusOK, gin.H{"status": "success", "message": "Welcome to Golang with PostgreSQL"})
|
|
|
|
})
|
|
|
|
|
|
|
|
log.Fatal(server.Run(":" + config.PostgresPort))*/
|
|
|
|
}
|