From 8879463cb94d33ba82d81f33f960a0d95d950882 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 28 Jan 2017 02:36:40 -0600 Subject: [PATCH] Switch config file to yaml --- dospin.go | 2 +- dospin.json | 20 -------------------- dospin.yaml | 26 ++++++++++++++++++++++++++ settings.go | 29 +++++++++++++++-------------- 4 files changed, 42 insertions(+), 35 deletions(-) delete mode 100644 dospin.json create mode 100644 dospin.yaml diff --git a/dospin.go b/dospin.go index 60c5c72..eebc3b2 100644 --- a/dospin.go +++ b/dospin.go @@ -27,7 +27,7 @@ type cmdOptions struct { func parseCmdOptions() cmdOptions { var o cmdOptions flag.StringVar(&o.cmd, "cmd", CMD_SERVE, "Mode to run command in ("+CMD_SERVE+","+CMD_SPINDOWNALL+")") - flag.StringVar(&o.config, "config", "dospin.json", "Path to the dospin config file") + flag.StringVar(&o.config, "config", "dospin.yaml", "Path to the dospin config file") flag.StringVar(&o.logFile, "logFile", "stdout", "Path to the dospin log file") flag.Parse() return o diff --git a/dospin.json b/dospin.json deleted file mode 100644 index db052e4..0000000 --- a/dospin.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "ApiToken": "", - "Servers": { - "minecraft": { - "Ports": [25565], - "UsePublicIP": false, - "InitialSize": "4gb", - "Size": "4gb", - "Region": "nyc1", - "SshKeys": [ - "Key1", - "gtalent2@gmail.com" - ], - "UsePersistentImage": false, - "ImageSlug": "ubuntu-16-04-x64", - "Volumes": ["volume-nyc1-01"], - "UserData": "#!/bin/bash\napt-get update\napt-get install -y docker.io\nmkdir -p /mnt/volume-nyc1-01\nmount -o discard,defaults /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 /mnt/volume-nyc1-01\necho /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 /mnt/volume-nyc1-01 ext4 defaults,nofail,discard 0 0 | tee -a /etc/fstab\ndocker run -d --restart=always -p 25565:25565 -v /mnt/volume-nyc1-01/minecraft-server:/minecraft-server -w /minecraft-server -t java:8-alpine sh start.sh" - } - } -} diff --git a/dospin.yaml b/dospin.yaml new file mode 100644 index 0000000..7324b0d --- /dev/null +++ b/dospin.yaml @@ -0,0 +1,26 @@ +--- +api_token: +servers: + minecraft: + ports: + - 25565 + use_public_ip: false + initial_size: 4gb + size: 4gb + region: nyc1 + ssh_keys: + - Key1 + - gtalent2@gmail.com + use_persistent_image: false + image_slug: ubuntu-16-04-x64 + volumes: + - volume-nyc1-01 + user_data: |- + #!/bin/bash + apt-get update + apt-get install -y docker.io + mkdir -p /mnt/volume-nyc1-01 + mount -o discard,defaults /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 /mnt/volume-nyc1-01 + echo /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 /mnt/volume-nyc1-01 ext4 defaults,nofail,discard 0 0 | tee -a /etc/fstab + docker run -d --restart=always -p 25565:25565 -v /mnt/volume-nyc1-01/minecraft-server:/minecraft-server -w /minecraft-server -t java:8-alpine sh start.sh + diff --git a/settings.go b/settings.go index 02b080e..c250e8b 100644 --- a/settings.go +++ b/settings.go @@ -8,26 +8,27 @@ package main import ( - "encoding/json" + "gopkg.in/yaml.v2" "io/ioutil" ) type Settings struct { - ApiToken string - Servers map[string]Server + ApiToken string `yaml:"api_token"` + Servers map[string]Server `yaml:"servers"` } type Server struct { - Ports []int - UsePublicIP bool - InitialSize string - Size string - Region string - UsePersistentImage bool - ImageSlug string - UserData string - SshKeys []string - Volumes []string + Ports []int `yaml:"ports"` + ActivityTimeoutMin int `yaml:"activity_timeout_min"` + UsePublicIP bool `yaml:"use_public_ip"` + InitialSize string `yaml:"initial_size"` + Size string `yaml:"size"` + Region string `yaml:"region"` + UsePersistentImage bool `yaml:"use_persistent_image"` + ImageSlug string `yaml:"image_slug"` + UserData string `yaml:"user_data"` + SshKeys []string `yaml:"ssh_keys"` + Volumes []string `yaml:"volumes"` } func loadSettings(path string) (Settings, error) { @@ -37,7 +38,7 @@ func loadSettings(path string) (Settings, error) { return s, err } - err = json.Unmarshal(data, &s) + err = yaml.Unmarshal(data, &s) if err != nil { return s, err }