dospin/settings.go

48 lines
1.2 KiB
Go
Raw Normal View History

2016-02-26 17:35:57 -06:00
/*
2017-01-25 17:59:25 -06:00
Copyright 2016-2017 gtalent2@gmail.com
2016-02-26 17:35:57 -06:00
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
2016-02-14 23:38:28 -06:00
package main
import (
2017-01-28 02:36:40 -06:00
"gopkg.in/yaml.v2"
2016-02-14 23:38:28 -06:00
"io/ioutil"
)
2016-02-15 00:18:56 -06:00
type Settings struct {
2017-01-28 02:36:40 -06:00
ApiToken string `yaml:"api_token"`
Servers map[string]Server `yaml:"servers"`
2016-02-14 23:38:28 -06:00
}
2016-02-28 01:03:16 -06:00
type Server struct {
2017-01-28 02:36:40 -06:00
Ports []int `yaml:"ports"`
2017-01-28 21:28:16 -06:00
ActivityTimeout string `yaml:"activity_timeout"`
2017-01-28 02:36:40 -06:00
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"`
2016-02-14 23:38:28 -06:00
}
2016-02-15 00:18:56 -06:00
func loadSettings(path string) (Settings, error) {
var s Settings
2016-02-14 23:38:28 -06:00
data, err := ioutil.ReadFile(path)
if err != nil {
return s, err
}
2017-01-28 02:36:40 -06:00
err = yaml.Unmarshal(data, &s)
2016-02-14 23:38:28 -06:00
if err != nil {
return s, err
}
return s, err
}