mirror of
https://github.com/michaellindman/discoupload.git
synced 2024-11-16 20:11:38 +00:00
36 lines
626 B
Go
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
|
||
|
}
|