Backend/modules/configs/serverConfig/serverConfig.go

54 lines
916 B
Go

package serverConfig
import (
"io/ioutil"
"log"
"gopkg.in/yaml.v3"
)
var Cfg Config
type Config struct {
Debug bool `yaml:"debug"`
KraSettingsConfigPath string `yaml:"kra_settings_config_path"`
MongoDB MongoDB `yaml:"mongodb"`
Servers Servers
}
type MongoDB struct {
Hostname string
Port string
Database string
Username string
Password string
}
type Servers struct {
MinecraftServer MinecraftServer `yaml:"minecraft"`
WebServer WebServer `yaml:"web"`
}
type MinecraftServer struct {
Host string
AccessKey string `yaml:"access_key"`
}
type WebServer struct {
Host string
}
func LoadServerConfig() {
file, err := ioutil.ReadFile("config.yaml")
if err != nil {
log.Println("failed to load yaml file", err)
}
err = yaml.Unmarshal(file, &Cfg)
if err != nil {
log.Fatal("failed to unmarshal config yaml", err)
}
}