subscribe-bot/config/config.go

52 lines
983 B
Go
Raw Normal View History

2020-10-12 13:47:28 +00:00
package config
2020-10-11 19:32:58 +00:00
import (
"fmt"
"io/ioutil"
"os"
"github.com/BurntSushi/toml"
)
type Config struct {
2020-10-12 14:25:50 +00:00
Debug bool `toml:"debug,omitempty"`
2020-10-11 19:32:58 +00:00
BotToken string `toml:"bot_token"`
2020-10-12 04:22:47 +00:00
Repos string `toml:"repos"`
2020-10-12 14:12:09 +00:00
DatabasePath string `toml:"db_path"`
2020-10-12 14:25:50 +00:00
Oauth OauthConfig `toml:"oauth"`
Web WebConfig `toml:"web"`
}
type OauthConfig struct {
ClientId int `toml:"client_id"`
ClientSecret string `toml:"client_secret"`
2020-10-12 14:12:09 +00:00
}
type WebConfig struct {
Host string `toml:"host"`
Port int `toml:"port"`
2020-10-11 19:32:58 +00:00
}
func ReadConfig(path string) (config Config, err error) {
file, err := os.Open(path)
if err != nil {
err = fmt.Errorf("couldn't open file %s: %w", path, err)
return
}
data, err := ioutil.ReadAll(file)
if err != nil {
err = fmt.Errorf("couldn't read data from %s: %w", path, err)
return
}
err = toml.Unmarshal(data, &config)
if err != nil {
err = fmt.Errorf("couldn't parse config data from %s: %w", path, err)
return
}
return
}