update logging

This commit is contained in:
Fran Jurmanović
2025-05-29 00:21:32 +02:00
parent 3dfbe77219
commit 1f41f6003b
7 changed files with 238 additions and 56 deletions

View File

@@ -3,6 +3,7 @@ package model
import (
"database/sql/driver"
"fmt"
"strconv"
)
type ServiceStatus int
@@ -54,14 +55,24 @@ func ParseServiceStatus(s string) ServiceStatus {
// MarshalJSON implements json.Marshaler interface
func (s ServiceStatus) MarshalJSON() ([]byte, error) {
return []byte(`"` + s.String() + `"`), nil
// Return the numeric value instead of string
return []byte(strconv.Itoa(int(s))), nil
}
// UnmarshalJSON implements json.Unmarshaler interface
func (s *ServiceStatus) UnmarshalJSON(data []byte) error {
// Try to parse as number first
if i, err := strconv.Atoi(string(data)); err == nil {
*s = ServiceStatus(i)
return nil
}
// Fallback to string parsing for backward compatibility
str := string(data)
// Remove quotes
str = str[1 : len(str)-1]
if len(str) >= 2 {
// Remove quotes if present
str = str[1 : len(str)-1]
}
*s = ParseServiceStatus(str)
return nil
}

View File

@@ -41,11 +41,12 @@ type State struct {
type ServerState struct {
sync.RWMutex
Session string `json:"session"`
SessionStart time.Time `json:"sessionStart"`
PlayerCount int `json:"playerCount"`
Track string `json:"track"`
MaxConnections int `json:"maxConnections"`
Session string `json:"session"`
SessionStart time.Time `json:"sessionStart"`
PlayerCount int `json:"playerCount"`
Track string `json:"track"`
MaxConnections int `json:"maxConnections"`
SessionDurationMinutes int `json:"sessionDurationMinutes"`
// Players map[int]*PlayerState
// etc.
}

View File

@@ -56,4 +56,5 @@ type StateHistory struct {
Session string `json:"session"`
PlayerCount int `json:"playerCount"`
DateCreated time.Time `json:"dateCreated"`
SessionDurationMinutes int `json:"sessionDurationMinutes"`
}