App config
This commit is contained in:
@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"machines/app/cfg"
|
||||
"machines/app/db"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@ -10,9 +11,6 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const HOST = "0.0.0.0"
|
||||
const PORT = 3000
|
||||
|
||||
func handlePing(c *gin.Context) {
|
||||
c.JSON(
|
||||
http.StatusOK,
|
||||
@ -56,6 +54,11 @@ func handleGetMachine(dbConn *gorm.DB) gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func handleGetMachineProducts(dbConn *gorm.DB) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func initRouter(dbConn *gorm.DB) *gin.Engine {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
router := gin.Default()
|
||||
@ -65,13 +68,15 @@ func initRouter(dbConn *gorm.DB) *gin.Engine {
|
||||
routes.GET("/ping", handlePing)
|
||||
routes.GET("", handleGetMachines(dbConn))
|
||||
routes.GET("/:machineId", handleGetMachine(dbConn))
|
||||
routes.GET("/:machineId/products", handleGetMachineProducts(dbConn))
|
||||
}
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
func Serve(dbConn *gorm.DB) {
|
||||
serverAddr := fmt.Sprintf("%s:%d", HOST, PORT)
|
||||
serverAddr := fmt.Sprintf("%s:%d", cfg.Config.AppHost, cfg.Config.AppPort)
|
||||
fmt.Printf("Starting serving on %s\n", serverAddr)
|
||||
|
||||
router := initRouter(dbConn)
|
||||
router.Run(serverAddr)
|
||||
|
||||
@ -5,11 +5,15 @@ import (
|
||||
)
|
||||
|
||||
type configStruct struct {
|
||||
DbHost string `default:"localhost"`
|
||||
DbPort int `default:"55432"`
|
||||
DbName string `default:"komponiranje"`
|
||||
DbUser string `default:"pero"`
|
||||
DbPassword string `default:"pero.000"`
|
||||
AppHost string `default:"0.0.0.0"`
|
||||
AppPort int `default:"3000"`
|
||||
DbHost string `default:"localhost"`
|
||||
DbPort int `default:"55432"`
|
||||
DbName string `default:"komponiranje"`
|
||||
DbUser string `default:"pero"`
|
||||
DbPassword string `default:"pero.000"`
|
||||
ProductsAppHost string `default:"localhost"`
|
||||
ProductsAppPort int `default:"3001"`
|
||||
}
|
||||
|
||||
const ENV_PREFIX = ""
|
||||
|
||||
Reference in New Issue
Block a user