Read topic from config

This commit is contained in:
Thorben Günther 2022-10-10 01:30:39 +02:00
parent 8347d6410f
commit bb1a71a637
No known key found for this signature in database
GPG key ID: 415CD778D8C5AFED
2 changed files with 15 additions and 3 deletions

View file

@ -1,10 +1,15 @@
package main package main
import "git.sr.ht/~emersion/go-scfg" import (
"fmt"
"git.sr.ht/~emersion/go-scfg"
)
type config struct { type config struct {
HTTPAddress string HTTPAddress string
LogLevel string LogLevel string
Topic string
} }
func readConfig(path string) (*config, error) { 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 return config, nil
} }

View file

@ -83,8 +83,7 @@ func (rcv *receiver) handleWebhooks(w http.ResponseWriter, r *http.Request) {
} }
client := &http.Client{Timeout: time.Second * 3} client := &http.Client{Timeout: time.Second * 3}
url := "https://ntfy.sh/alertmanager_test" req, err := http.NewRequest(http.MethodPost, rcv.cfg.Topic, strings.NewReader(body))
req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(body))
if err != nil { if err != nil {
rcv.logger.Error(err) rcv.logger.Error(err)
} }