Implemented better config system
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-11-16 05:20:59 +01:00
parent 644f038732
commit 9f4be2d76e
12 changed files with 135 additions and 875 deletions

View File

@@ -0,0 +1,5 @@
package ntfy
type Config struct {
Presence string `yaml:"presence" envconfig:"NTFY_PRESENCE"`
}

View File

@@ -3,12 +3,11 @@ package ntfy
import (
"fmt"
"net/http"
"os"
"strings"
)
type ntfy struct {
topic string
presence string
}
func (ntfy *ntfy) Presence(home bool) {
@@ -23,7 +22,7 @@ func (ntfy *ntfy) Presence(home bool) {
actions = "broadcast, Set as home, extras.cmd=presence, extras.state=1, clear=true"
}
req, err := http.NewRequest("POST", fmt.Sprintf("https://ntfy.sh/%s", ntfy.topic), strings.NewReader(description))
req, err := http.NewRequest("POST", fmt.Sprintf("https://ntfy.sh/%s", ntfy.presence), strings.NewReader(description))
if err != nil {
panic(err)
}
@@ -36,9 +35,8 @@ func (ntfy *ntfy) Presence(home bool) {
http.DefaultClient.Do(req)
}
func Connect() ntfy {
topic, _ := os.LookupEnv("NTFY_TOPIC")
ntfy := ntfy{topic}
func Connect(config Config) ntfy {
ntfy := ntfy{presence: config.Presence}
// @TODO Make sure the topic is valid?