config: use ko

This commit is contained in:
Stanislav Seletskiy
2019-07-31 01:35:17 +03:00
parent 4fc1aa6553
commit ebe2b3a830
3 changed files with 45 additions and 58 deletions

27
config.go Normal file
View File

@@ -0,0 +1,27 @@
package main
import (
"os"
"github.com/kovetskiy/ko"
)
type Config struct {
Username string `env:"MARK_USERNAME" toml:"username"`
Password string `env:"MARK_PASSWORD" toml:"password"`
BaseURL string `env:"MARK_BASE_URL" toml:"base_url"`
}
func LoadConfig(path string) (*Config, error) {
config := &Config{}
err := ko.Load(path, config)
if err != nil {
if os.IsNotExist(err) {
return config, nil
}
return nil, err
}
return config, nil
}