Files
factoryman/config.go
Raum0x2A aef97fe613 Added path checks and updated config
- Cleaned up func main()
- Separated config into two sections server and factoryman
- Updated backup.go to reflect changes to config file
- Updated config.go to reflect changes to config.yml as well as added a check to paths in config.yml
- Updated launch.go to reflect changes to config
move cli handler from main to cli.go
2026-04-29 11:39:55 -06:00

77 lines
1.7 KiB
Go

package main
import (
"errors"
"fmt"
"log"
"os"
"gopkg.in/yaml.v3"
)
const fmConfig = "config.yml"
type GoConfig struct {
Server struct {
ServDir string `yaml:"serverFolder"`
WorldFile string `yaml:"worldFile"`
ServCfg string `yaml:"serverSettings"`
ServExec string `yaml:"serverExec"`
} `yaml:"server"`
Factoryman struct {
ServPort int `yaml:"port"`
BackupDir string `yaml:"backupDir"`
UseScreen bool `yaml:"screen"`
ScreenName string `yaml:"screenName"`
} `yaml:"factoryman"`
}
func readCfg(factCfg string) GoConfig {
//read config file (YAML)
fileBytes, err := os.ReadFile(factCfg)
if err != nil {
log.Fatalf("Error reading config file: %v", err)
}
// return Struct
var config GoConfig
err = yaml.Unmarshal(fileBytes, &config)
if err != nil {
log.Fatalf("Error unmarshalling YAML file: %v", err)
}
return config
}
func isItReal(path string) bool {
if _, err := os.Stat(path); err == nil {
return true
} else if errors.Is(err, os.ErrNotExist) {
return false
} else {
return false
}
}
func verifyConfig(config GoConfig) bool {
if !isItReal(config.Server.ServDir) {
fmt.Printf("PATH NOT FOUND: %s", config.Server.ServDir)
return false
}
if !isItReal(config.Server.WorldFile) {
fmt.Printf("PATH NOT FOUND: %s", config.Server.WorldFile)
return false
}
if !isItReal(config.Server.ServCfg) {
fmt.Printf("PATH NOT FOUND: %s", config.Server.ServCfg)
return false
}
if !isItReal(config.Server.ServExec) {
fmt.Printf("PATH NOT FOUND: %s", config.Server.ServExec)
return false
}
if !isItReal(config.Factoryman.BackupDir) {
fmt.Printf("PATH NOT FOUND: %s", config.Factoryman.BackupDir)
return false
}
return true
}