1
0
mirror of https://github.com/michaellindman/discoupload.git synced 2024-12-18 19:04:29 +00:00
discoupload/config.go
Michael e6ab2a69c4 First commit
Signed-off-by: Michael <michael.lindman@gmail.com>
2020-08-02 04:13:39 +01:00

36 lines
626 B
Go

package main
import (
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
// Config Application Config
type Config struct {
API struct {
URL string `yaml:"url"`
Key string `yaml:"key"`
Username string `yaml:"username"`
}
}
// NewConfig - Create a new app config
func NewConfig(configFile string) (cfg *Config, err error) {
var config *Config
file, err := os.Open(configFile)
if err != nil {
return nil, err
}
defer file.Close()
byteValue, err := ioutil.ReadAll(file)
if err != nil {
return nil, err
}
if err = yaml.Unmarshal(byteValue, &config); err != nil {
return nil, err
}
return config, nil
}