Bugfixes. Optimizations/refactor. Add redis for player-cache. Add docker files. Replace sqlite dep. Single-Calc for existing players. Game-Metrics in JSON.

This commit is contained in:
MaxJa4
2024-01-21 00:49:20 +01:00
parent 069d76520e
commit da1108d441
41 changed files with 1154 additions and 203 deletions

15
main.go
View File

@@ -53,10 +53,14 @@ func init() {
if err != nil {
log.Fatal(err)
}
controllers.LoadMetrics()
}
func main() {
//gin.SetMode(gin.ReleaseMode) // uncomment upon release
if os.Getenv("GO_ENV") == "production" {
gin.SetMode(gin.ReleaseMode)
}
router := gin.New()
err := router.SetTrustedProxies([]string{"127.0.0.1"})
@@ -72,6 +76,13 @@ func main() {
models.ConnectDatabase()
models.ConnectCache()
var code models.ActivationCode
if err := models.DB.First(&code).Error; err != nil {
firstCode := utils.GenerateActivationCode()
models.DB.Create(&models.ActivationCode{Code: firstCode, UserRole: models.AdminRole})
log.Println("Created first activation code with ADMIN role:\n" + firstCode)
}
f, _ := os.OpenFile("isc_rest.log", os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
utils.GinWriter = io.MultiWriter(f, os.Stdout)
router.Use(
@@ -114,6 +125,8 @@ func main() {
protected.GET("/cache/:player_id", controllers.GetCacheByPlayerID)
protected.GET("/score/:player_id", controllers.GetScoreByPlayerID)
protected.GET("/game", controllers.GetGames)
protected.GET("/game_html", controllers.GetGamesHTML)