refactor(controller): added env and other fixes to account for running as a service

This commit is contained in:
2025-09-08 16:08:30 -05:00
parent ddfeb5ccb5
commit fc7ecb6ab6
4 changed files with 43 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"
"time"
"github.com/gin-gonic/gin"
@@ -14,14 +15,12 @@ import (
func main() {
err := godotenv.Load("../.env")
if err != nil {
fmt.Println("Warning: .env file not found")
}
exePath, _ := os.Executable()
exeDir := filepath.Dir(exePath)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
if err := godotenv.Load(filepath.Join(exeDir, ".env")); err != nil {
// fallback dev path
_ = godotenv.Load("../.env")
}
// gin stuff
@@ -30,6 +29,11 @@ func main() {
basePath = "/lst/api/controller"
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
server := socketio.NewServer(nil)
r := Setup(basePath, server) // returns *gin.Engine