From bb1a71a637160851784d4a60382b8dd4e77f526e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Mon, 10 Oct 2022 01:30:39 +0200 Subject: [PATCH] Read topic from config --- config.go | 15 ++++++++++++++- main.go | 3 +-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index 9cfa67a..02c22f5 100644 --- a/config.go +++ b/config.go @@ -1,10 +1,15 @@ package main -import "git.sr.ht/~emersion/go-scfg" +import ( + "fmt" + + "git.sr.ht/~emersion/go-scfg" +) type config struct { HTTPAddress string LogLevel string + Topic string } func readConfig(path string) (*config, error) { @@ -32,5 +37,13 @@ func readConfig(path string) (*config, error) { } } + d = cfg.Get("topic") + if d == nil { + return nil, fmt.Errorf("%q missing from config", "topic") + } + if err := d.ParseParams(&config.Topic); err != nil { + return nil, err + } + return config, nil } diff --git a/main.go b/main.go index 628f13a..740b5fe 100644 --- a/main.go +++ b/main.go @@ -83,8 +83,7 @@ func (rcv *receiver) handleWebhooks(w http.ResponseWriter, r *http.Request) { } client := &http.Client{Timeout: time.Second * 3} - url := "https://ntfy.sh/alertmanager_test" - req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(body)) + req, err := http.NewRequest(http.MethodPost, rcv.cfg.Topic, strings.NewReader(body)) if err != nil { rcv.logger.Error(err) }