gruik

Fork of GCU-Squad's RSS-to-IRC bridge
git clone https://git.instinctive.eu/gruik.git
Log | Files | Refs | README | LICENSE

commit 893f060181f9aa836c063396efe84965a3ed3f1e
parent c5b38665ae24c0773eefa73e68e820dd17e3739e
Author: Emile 'iMil' Heitor <imil@NetBSD.org>
Date:   Tue, 11 Jul 2023 16:41:13 +0200

feat: live conf reload

Diffstat:
Mmain.go | 7++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/main.go b/main.go @@ -15,8 +15,8 @@ import ( func newsFetch(client *girc.Client, channel string) { // Fetch and post news from RSS feeds - feeds := viper.GetStringSlice("feeds.urls") frequency := viper.GetDuration("news_frequency") + maxnews := viper.GetInt("feeds.maxnews") postedItems := make(map[string]bool) @@ -35,7 +35,7 @@ func newsFetch(client *girc.Client, channel string) { if time.Since(start) > oneDay { postedItems = make(map[string]bool) } - for _, feedURL := range feeds { + for _, feedURL := range viper.GetStringSlice("feeds.urls") { log.Printf("fetching %s...\n", feedURL) fp := gofeed.NewParser() feed, err := fp.ParseURL(feedURL) @@ -53,7 +53,7 @@ func newsFetch(client *girc.Client, channel string) { continue } i++ - if i > viper.GetInt("feeds.maxnews") { + if i > maxnews { log.Println("too many lines to post") break } @@ -75,6 +75,7 @@ func main() { viper.SetConfigName("config") viper.SetConfigType("yaml") viper.AddConfigPath(".") + viper.WatchConfig() if err := viper.ReadInConfig(); err != nil { log.Fatalf("Failed to read configuration file: %s", err)