Read topic from config
This commit is contained in:
parent
8347d6410f
commit
bb1a71a637
2 changed files with 15 additions and 3 deletions
15
config.go
15
config.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
3
main.go
3
main.go
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue