42 lines
813 B
Go
42 lines
813 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
type Config struct {
|
|
BaseUrl string `toml:"base_url"`
|
|
SessionSecret string `toml:"session_secret"`
|
|
Oauth OauthConfig `toml:"oauth"`
|
|
}
|
|
|
|
type OauthConfig struct {
|
|
ClientId string `toml:"client_id"`
|
|
ClientSecret string `toml:"client_secret"`
|
|
}
|
|
|
|
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
|
|
}
|