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:
32
controllers/metrics_controller.go
Normal file
32
controllers/metrics_controller.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"InfantrySkillCalculator/models"
|
||||
"InfantrySkillCalculator/utils"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func LoadMetrics() {
|
||||
f, err := os.Open("./config/metrics.json")
|
||||
if err != nil {
|
||||
log.Fatal("Failed to open metrics.json: ", err)
|
||||
}
|
||||
defer func(f *os.File) {
|
||||
_ = f.Close()
|
||||
}(f)
|
||||
|
||||
data, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to read metrics.json: ", err)
|
||||
}
|
||||
|
||||
var metrics models.GameMetrics
|
||||
if err := json.Unmarshal(data, &metrics); err != nil {
|
||||
log.Fatal("Failed to deserialize metrics.json: ", err)
|
||||
}
|
||||
|
||||
utils.GameMetrics = metrics
|
||||
}
|
||||
Reference in New Issue
Block a user