gosocketio/config/config.go

52 lines
1.1 KiB
Go

package config
import (
"encoding/json"
"os"
"git.pyer.club/kingecg/gologger"
)
type ServerConfig struct {
Host string `json:"host"`
Port int `json:"port"`
Path string `json:"path"`
NameSpace string `json:"namespace"`
Logging gologger.LoggersConfig `json:"logging"`
}
var config ServerConfig = ServerConfig{
Host: "0.0.0.0",
Port: 8080,
Path: "/socket.io/",
NameSpace: "/",
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
}