gosocketio/config/config.go

52 lines
1.1 KiB
Go
Raw Normal View History

2023-11-28 21:42:07 +08:00
package config
import (
"encoding/json"
"os"
"git.pyer.club/kingecg/gologger"
)
type ServerConfig struct {
2023-11-30 17:38:20 +08:00
Host string `json:"host"`
Port int `json:"port"`
Path string `json:"path"`
NameSpace string `json:"namespace"`
Logging gologger.LoggersConfig `json:"logging"`
2023-11-28 21:42:07 +08:00
}
var config ServerConfig = ServerConfig{
2023-11-30 17:38:20 +08:00
Host: "0.0.0.0",
Port: 8080,
Path: "/socket.io/",
NameSpace: "/",
2023-11-28 21:42:07 +08:00
Logging: gologger.LoggersConfig{
Appenders: map[string]gologger.LogAppenderConfig{
"out": gologger.LogAppenderConfig{
Type: "console",
},
},
Categories: map[string]gologger.LogConfig{
"default": {
Level: "debug",
Appenders: []string{"out"},
}},
},
}
func LoadConfig(configFile string) {
// read config gile content and parse it as json
configContent, err := os.ReadFile(configFile)
if err != nil {
panic(err)
}
err = json.Unmarshal(configContent, &config)
if err != nil {
panic(err)
}
}
func GetConfig() *ServerConfig {
return &config
}