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"
|
"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 {
|
func readCfg(factCfg string) UsrConfig {
|
||||||
//read config file (YAML)
|
//read config file (YAML)
|
||||||
fileBytes, err := os.ReadFile(factCfg)
|
fileBytes, err := os.ReadFile(factCfg)
|
||||||
if err != nil {
|
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
|
// return Struct
|
||||||
var config UsrConfig
|
var config UsrConfig
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
server:
|
server:
|
||||||
serverFolder: "factorio"
|
serverFolder: "factorio"
|
||||||
worldFile: ""
|
worldFile: "factorio/saves/newworld.zip"
|
||||||
serverSettings: "factorio/data/server-settings.json"
|
serverSettings: "factorio/data/server-settings.json"
|
||||||
serverExec: "factorio/bin/x64/factorio"
|
serverExec: "factorio/bin/x64/factorio"
|
||||||
port: 34197
|
port: 34197
|
||||||
|
|||||||
BIN
factoryman
BIN
factoryman
Binary file not shown.
18
structs.go
18
structs.go
@@ -19,6 +19,24 @@ type UsrConfig struct {
|
|||||||
} `yaml:"factoryman"`
|
} `yaml:"factoryman"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DefConfig struct {
|
||||||
|
Server struct { // server specific settings
|
||||||
|
ServDir string
|
||||||
|
WorldFile string
|
||||||
|
ServCfg string
|
||||||
|
ServExec string
|
||||||
|
ServPort int
|
||||||
|
}
|
||||||
|
|
||||||
|
Factoryman struct { // factoryman settings
|
||||||
|
BackupDir string
|
||||||
|
UseScreen bool
|
||||||
|
ScreenName string
|
||||||
|
UserName string
|
||||||
|
ApiToken string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// JSON file from config
|
// JSON file from config
|
||||||
type Mod struct {
|
type Mod struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|||||||
Reference in New Issue
Block a user