owncast-webhook/config/config.go

51 lines
1,003 B
Go

package config
import (
"log"
"gopkg.in/ini.v1"
)
type Config struct {
Server struct {
BaseUrl string
Address string
WebhookSecret string
Port int
}
Owncast struct {
BaseUrl string
}
Twitch struct {
Enable bool
Channel string
}
}
var config *Config
func Get() *Config {
if config == nil {
config = &Config{}
}
return config
}
func (c *Config) Load(file string) {
cfg, err := ini.Load(file)
if err != nil {
log.Fatal(err)
}
config.Server.Address = cfg.Section("server").Key("address").String()
config.Server.Port, _ = cfg.Section("server").Key("port").Int()
config.Server.BaseUrl = cfg.Section("server").Key("base_url").String()
config.Server.WebhookSecret = cfg.Section("server").Key("webhook_secret").String()
config.Owncast.BaseUrl = cfg.Section("owncast").Key("base_url").String()
config.Twitch.Enable = cfg.Section("twitch").Key("enable").MustBool(false)
config.Twitch.Channel = cfg.Section("twitch").Key("channel").String()
}