Compare commits

..

2 Commits

Author SHA1 Message Date
9e7bd21602 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: ""
2026-05-04 12:41:18 -06:00
e051d2d6f6 Changed GoConfig to UsrConfig
Changed GoConfig struct to UsrConfig
2026-05-04 11:50:08 -06:00
7 changed files with 43 additions and 11 deletions

View File

@@ -7,7 +7,7 @@ import (
"time"
)
func backUp(cmd string, c GoConfig) {
func backUp(cmd string, c UsrConfig) {
switch cmd {
case "full":
fmt.Println("Starting full server backup")

4
cli.go
View File

@@ -19,9 +19,7 @@ func cliToolMode() {
startStopServer("stop", c)
}
case "help", "h", "--help", "-h":
fmt.Printf("Start Server: %s start\nStop Server: %s stop\n", os.Args[0], os.Args[0])
fmt.Printf("Run backup\n\tFull backup: %s backup full", os.Args[0])
fmt.Printf("\n\tBackup saves: %s backup saves\n", os.Args[0])
fmt.Printf("Start Server: %s start\nStop Server: %s stop\nRun backup\n\tFull backup: %s backup full\n\tBackup saves: %s backup saves\n", os.Args[0], os.Args[0], os.Args[0], os.Args[0])
case "download":
if len(os.Args) > 2 {
switch os.Args[2] {

View File

@@ -9,14 +9,30 @@ import (
"gopkg.in/yaml.v3"
)
func readCfg(factCfg string) GoConfig {
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 GoConfig
var config UsrConfig
err = yaml.Unmarshal(fileBytes, &config)
if err != nil {
log.Fatalf("Error unmarshalling YAML file: %v", err)
@@ -32,7 +48,7 @@ func isItReal(path string) bool { //check if path exists
return false
}
}
func verifyConfig(config GoConfig) bool { // check each file/dir to see if it exists
func verifyConfig(config UsrConfig) bool { // check each file/dir to see if it exists
if !isItReal(config.Server.ServDir) { //check for Server directory
fmt.Printf("PATH NOT FOUND: %s", config.Server.ServDir)
return false

View File

@@ -1,6 +1,6 @@
server:
serverFolder: "factorio"
worldFile: ""
worldFile: "factorio/saves/newworld.zip"
serverSettings: "factorio/data/server-settings.json"
serverExec: "factorio/bin/x64/factorio"
port: 34197

Binary file not shown.

View File

@@ -7,7 +7,7 @@ import (
"os/exec"
)
func startStopServer(cmd string, con GoConfig) {
func startStopServer(cmd string, con UsrConfig) {
switch cmd {
case "start":
x := fmt.Sprintf("%s --port %d --server-settings %s --start-server %s", con.Server.ServExec, con.Server.ServPort, con.Server.ServCfg, con.Server.WorldFile)

View File

@@ -1,7 +1,7 @@
package main
// config struct
type GoConfig struct {
type UsrConfig struct {
Server struct { // server specific settings
ServDir string `yaml:"serverFolder"`
WorldFile string `yaml:"worldFile"`
@@ -19,6 +19,24 @@ type GoConfig struct {
} `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
type Mod struct {
Name string `json:"name"`