| 1 | package gotifyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/ |
| 2 | |
| 3 | import "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 4 | |
| 5 | // URLBuilder handles URL construction for Gotify API endpoints. |
| 6 | type URLBuilderscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/URLBuilder# interface { |
| 7 | BuildURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/URLBuilder#BuildURL.(config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#) (string, error) |
| 8 | } |
| 9 | |
| 10 | // DefaultURLBuilder provides the default implementation of URLBuilder. |
| 11 | type DefaultURLBuilderscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/DefaultURLBuilder# struct{} |
| 12 | |
| 13 | // BuildURL constructs the Gotify API URL with scheme, host, path, and token. |
| 14 | // This function builds the complete endpoint URL for the Gotify message API, handling |
| 15 | // different authentication methods (header vs query parameter) and TLS settings. |
| 16 | // The URL format depends on whether header authentication is enabled. |
| 17 | // Parameters: |
| 18 | // - config: Configuration containing host, path, token, and authentication settings |
| 19 | // |
| 20 | // Returns: complete API URL string. |
| 21 | func (b *DefaultURLBuilderscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/DefaultURLBuilder#) BuildURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/DefaultURLBuilder#BuildURL().(config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#) (string, error) { |
| 22 | // Determine URL scheme based on TLS settings |
| 23 | scheme := "https" |
| 24 | if config.DisableTLSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#DisableTLS. { |
| 25 | scheme = "http" // Use HTTP scheme when TLS verification is disabled |
| 26 | } |
| 27 | |
| 28 | // Construct URL using url.URL for proper encoding |
| 29 | apiURL := &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 30 | Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme.: scheme, |
| 31 | Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: config.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Host., |
| 32 | Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.: config.Pathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Path. + "/message", |
| 33 | } |
| 34 | |
| 35 | if !config.UseHeaderscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#UseHeader. { |
| 36 | // Query parameter authentication: include token in URL query string |
| 37 | q := apiURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().() |
| 38 | q.Setscip-go gomod github.com/golang/go/src . `net/url`/Values#Set().("token", config.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Token.) |
| 39 | apiURL.RawQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#RawQuery. = q.Encodescip-go gomod github.com/golang/go/src . `net/url`/Values#Encode().() |
| 40 | } |
| 41 | |
| 42 | return apiURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().(), nil |
| 43 | } |