Skip to content

Commit

Permalink
#6: Fix Gotify URL handling
Browse files Browse the repository at this point in the history
  • Loading branch information
saaste committed Apr 14, 2024
1 parent ce7eb9d commit 4550b52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ func LoadConfig() (*AppConfig, error) {

appConfig.AppVersion = appVersion

// Validate base URL
if appConfig.GotifyEnabled && (appConfig.GotifyToken == "" || appConfig.GotifyURL == "") {
return nil, fmt.Errorf("gotify notifications are enabled but token or gotify URL is empty")
}

// Validate trailing slash of URLS
if !strings.HasSuffix(appConfig.BaseURL, "/") {
return nil, fmt.Errorf("base URL must have a trailing slash")
appConfig.BaseURL = fmt.Sprintf("%s/", appConfig.BaseURL)
}
if appConfig.GotifyURL != "" && !strings.HasSuffix(appConfig.GotifyURL, "/") {
appConfig.GotifyURL = fmt.Sprintf("%s/", appConfig.GotifyURL)
}

return appConfig, nil
Expand Down
2 changes: 1 addition & 1 deletion notifications/gotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (n *Notifier) SendGotifyMessage(title string, message string) error {
return fmt.Errorf("marshaling request body failed: %w", err)
}

gotifyUrl := fmt.Sprintf("%s/message", n.appConfig.GotifyURL)
gotifyUrl := fmt.Sprintf("%smessage", n.appConfig.GotifyURL)
req, err := http.NewRequest(http.MethodPost, gotifyUrl, bytes.NewBuffer(data))
if err != nil {
return fmt.Errorf("creating a request failed: %w", err)
Expand Down

0 comments on commit 4550b52

Please sign in to comment.