36 lines
523 B
Go
36 lines
523 B
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
"log"
|
||
|
|
||
|
"gopkg.in/yaml.v2"
|
||
|
)
|
||
|
|
||
|
var Cfg Config
|
||
|
|
||
|
type Config struct {
|
||
|
Bot Bot
|
||
|
}
|
||
|
|
||
|
type Bot struct {
|
||
|
HomeserverUrl string `yaml:"homeserver_url"`
|
||
|
User string
|
||
|
Password string
|
||
|
RoomId string `yaml:"room_id"`
|
||
|
}
|
||
|
|
||
|
func LoadConfig() {
|
||
|
file, err := ioutil.ReadFile("../go-chat-bot/config.yaml")
|
||
|
|
||
|
if err != nil {
|
||
|
log.Fatalln("failed to load yaml file", err)
|
||
|
}
|
||
|
|
||
|
err = yaml.Unmarshal(file, &Cfg)
|
||
|
|
||
|
if err != nil {
|
||
|
log.Fatalln("failed to unmarshal config", err)
|
||
|
}
|
||
|
}
|