refactor(controller): added env and other fixes to account for running as a service
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user