Location, location, location.
continuous-integration/drone Build is passing

This commit is contained in:
Stian Fredrik Aune
2022-01-21 19:26:06 +01:00
parent 15536c6078
commit a08685c3cd
3 changed files with 27 additions and 5 deletions
+18 -1
View File
@@ -1,17 +1,34 @@
package config
import (
"log"
"os"
"strconv"
"time"
)
func Location() *time.Location {
env, ok := os.LookupEnv("LUCIFER_LOCATION")
if !ok {
return time.UTC
}
loc, err := time.LoadLocation(env)
if err != nil {
log.Printf("Location lookup failed: %s (%s)", env, err.Error())
return time.UTC
}
return loc
}
func MySqlHost() string { return strEnv("LUCIFER_MYSQL_HOST") }
func MySqlPort() int { return intEnv("LUCIFER_MYSQL_PORT") }
func MySqlSchema() string { return strEnv("LUCIFER_MYSQL_SCHEMA") }
func MySqlUsername() string { return strEnv("LUCIFER_MYSQL_USERNAME") }
func MySQlPassword() string { return strEnv("LUCIFER_MYSQL_PASSWORD") }
func ServerPort() int { return intEnv("LUCIFER_SERVER_PORT") }
func ServerPort() int { return intEnv("LUCIFER_SERVER_PORT") }
func strEnv(key string) string {
env, ok := os.LookupEnv(key)
+4 -1
View File
@@ -7,13 +7,14 @@ import (
"git.aiterp.net/lucifer/new-server/app/config"
"git.aiterp.net/lucifer/new-server/app/services"
"git.aiterp.net/lucifer/new-server/app/services/publisher"
"git.aiterp.net/lucifer/new-server/models"
"github.com/gin-gonic/gin"
"log"
"time"
)
func StartServer() {
setupCtx, cancel := context.WithTimeout(context.Background(), time.Second * 10)
setupCtx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
err := publisher.Initialize(setupCtx)
@@ -38,5 +39,7 @@ func StartServer() {
api.EventHandlers(apiGin.Group("/event-handlers"))
api.Scenes(apiGin.Group("/scenes"))
models.TimeOfDayTimeZone = config.Location()
log.Fatal(ginny.Run(fmt.Sprintf("0.0.0.0:%d", config.ServerPort())))
}