Added default config if config.yml is missing
Default config: server: serverFolder: "factorio" worldFile: "factorio/saves/newworld.zip" serverSettings: "factorio/data/server-settings.json" serverExec: "factorio/bin/x64/factorio" port: 34197 factoryman: screen: True screenName: "Factorio" backupDir: "factorio/backups" username: "" apitoken: ""
This commit is contained in:
18
config.go
18
config.go
@@ -9,11 +9,27 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func DefCfg() *DefConfig {
|
||||
c := &DefConfig{}
|
||||
// server settings
|
||||
c.Server.ServDir = "factorio"
|
||||
c.Server.ServPort = 34197
|
||||
c.Server.ServCfg = "factorio/data/server-settings.json"
|
||||
c.Server.ServExec = "factorio/bin/x64/factorio"
|
||||
c.Server.WorldFile = "factorio/saves/newworld.zip"
|
||||
c.Factoryman.UseScreen = true
|
||||
c.Factoryman.ScreenName = "factorio"
|
||||
c.Factoryman.BackupDir = "factorio/backups"
|
||||
c.Factoryman.UserName = ""
|
||||
c.Factoryman.ApiToken = ""
|
||||
return c
|
||||
}
|
||||
func readCfg(factCfg string) UsrConfig {
|
||||
//read config file (YAML)
|
||||
fileBytes, err := os.ReadFile(factCfg)
|
||||
if err != nil {
|
||||
log.Fatalf("Error reading config file: %v", err)
|
||||
fmt.Printf("Error reading config.yml file, using defaults\n")
|
||||
return UsrConfig(*DefCfg())
|
||||
}
|
||||
// return Struct
|
||||
var config UsrConfig
|
||||
|
||||
Reference in New Issue
Block a user