42 lines
642 B
Go
42 lines
642 B
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
"log"
|
||
|
|
||
|
"gopkg.in/yaml.v2"
|
||
|
)
|
||
|
|
||
|
var Cfg Config
|
||
|
|
||
|
type Config struct {
|
||
|
Pages []PageItem `yaml:"pages,flow"`
|
||
|
Bot Bot
|
||
|
}
|
||
|
|
||
|
type PageItem struct {
|
||
|
Page string
|
||
|
UpdateTime []string `yaml:"update_time,flow"`
|
||
|
}
|
||
|
|
||
|
type Bot struct {
|
||
|
HomeserverUrl string `yaml:"homeserver_url"`
|
||
|
User string
|
||
|
Password string
|
||
|
RoomId string `yaml:"room_id"`
|
||
|
}
|
||
|
|
||
|
func LoadConfig() {
|
||
|
file, err := ioutil.ReadFile("./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)
|
||
|
}
|
||
|
}
|