update caching and server creation
This commit is contained in:
@@ -3,6 +3,7 @@ package model
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
@@ -106,6 +107,26 @@ type Configuration struct {
|
||||
ConfigVersion IntString `json:"configVersion"`
|
||||
}
|
||||
|
||||
type SystemConfig struct {
|
||||
ID uint `json:"id"`
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
DefaultValue string `json:"defaultValue"`
|
||||
Description string `json:"description"`
|
||||
DateModified string `json:"dateModified"`
|
||||
}
|
||||
|
||||
// Known configuration keys
|
||||
const (
|
||||
ConfigKeySteamCMDPath = "steamcmd_path"
|
||||
ConfigKeyNSSMPath = "nssm_path"
|
||||
)
|
||||
|
||||
// Cache keys
|
||||
const (
|
||||
CacheKeySystemConfig = "system_config_%s" // Format with config key
|
||||
)
|
||||
|
||||
func (i *IntString) UnmarshalJSON(b []byte) error {
|
||||
var str string
|
||||
if err := json.Unmarshal(b, &str); err == nil {
|
||||
@@ -136,4 +157,36 @@ func (i IntString) ToString() string {
|
||||
|
||||
func (i IntString) ToInt() (int) {
|
||||
return int(i)
|
||||
}
|
||||
|
||||
func (c *SystemConfig) Validate() error {
|
||||
if c.Key == "" {
|
||||
return fmt.Errorf("key is required")
|
||||
}
|
||||
|
||||
// Validate paths exist for certain config keys
|
||||
switch c.Key {
|
||||
case ConfigKeySteamCMDPath, ConfigKeyNSSMPath:
|
||||
if c.Value == "" {
|
||||
if c.DefaultValue == "" {
|
||||
return fmt.Errorf("value or default value is required for path configuration")
|
||||
}
|
||||
// Use default value if value is empty
|
||||
c.Value = c.DefaultValue
|
||||
}
|
||||
|
||||
// Check if path exists
|
||||
if _, err := os.Stat(c.Value); os.IsNotExist(err) {
|
||||
return fmt.Errorf("path does not exist: %s", c.Value)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *SystemConfig) GetEffectiveValue() string {
|
||||
if c.Value != "" {
|
||||
return c.Value
|
||||
}
|
||||
return c.DefaultValue
|
||||
}
|
||||
Reference in New Issue
Block a user