Debian Codegraph @

pkg/services/push/ntfy/ntfy.go

raw symbols SCIP
1 package ntfyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/
2
3 import (
4 "crypto/tlsscip-go gomod github.com/golang/go/src . `crypto/tls`/"
5 "encoding/base64scip-go gomod github.com/golang/go/src . `encoding/base64`/"
6 "fmtscip-go gomod github.com/golang/go/src . fmt/"
7 "net/httpscip-go gomod github.com/golang/go/src . `net/http`/"
8 "net/urlscip-go gomod github.com/golang/go/src . `net/url`/"
9 "stringsscip-go gomod github.com/golang/go/src . strings/"
10 "timescip-go gomod github.com/golang/go/src . time/"
11
12 "github.com/nicholas-fedor/shoutrrr/internal/metascip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/internal/meta`/"
13 "github.com/nicholas-fedor/shoutrrr/pkg/formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/"
14 "github.com/nicholas-fedor/shoutrrr/pkg/services/standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/"
15 "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/"
16 "github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/"
17 )
18
19 // Service sends notifications to ntfy.
20 type Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service# struct {
21 standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/.Standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Standard.
22
23 Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Config. *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#
24 pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#pkr. formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.PropKeyResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/PropKeyResolver#
25 httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#httpClient. typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient#
26 clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#client. jsonclientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/.Clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#
27 }
28
29 // HTTPTimeout defines the HTTP client timeout in seconds.
30 const HTTPTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/HTTPTimeout. = 10
31
32 // GetID returns the service identifier.
33 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#) GetIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#GetID().() string {
34 return Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Scheme.
35 }
36
37 // Initialize configures the service with a URL and logger.
38 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#) Initializescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Initialize().(serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#, logger typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.StdLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/StdLogger#) error {
39 s.SetLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Logger#SetLogger().(logger)
40 s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Config. = &Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#{}
41 s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#pkr. = formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.NewPropKeyResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/NewPropKeyResolver().(s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Config.)
42
43 if err := s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#pkr..SetDefaultPropsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/PropKeyResolver#SetDefaultProps().(s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Config.); err != nil {
44 return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("setting default props: %w", err)
45 }
46
47 err := s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Config..setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#setURL().(&s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#pkr., serviceURL)
48 if err != nil {
49 return err
50 }
51
52 // Force HTTP scheme when DisableTLS is true
53 if s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Config..DisableTLSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#DisableTLS. {
54 s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Config..Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Scheme. = "http"
55 }
56
57 // Configure HTTP transport: skip TLS verification if disabled, enforce TLS 1.2 minimum
58 if s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Config..DisableTLSVerificationscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#DisableTLSVerification. {
59 if s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#httpClient. == nil {
60 s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#httpClient. = &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{
61 Timeoutscip-go gomod github.com/golang/go/src . `net/http`/Client#Timeout.: HTTPTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/HTTPTimeout. * timescip-go gomod github.com/golang/go/src . time/.Secondscip-go gomod github.com/golang/go/src . time/Second.,
62 Transportscip-go gomod github.com/golang/go/src . `net/http`/Client#Transport.: &httpscip-go gomod github.com/golang/go/src . `net/http`/.Transportscip-go gomod github.com/golang/go/src . `net/http`/Transport#{
63 TLSClientConfigscip-go gomod github.com/golang/go/src . `net/http`/Transport#TLSClientConfig.: &tlsscip-go gomod github.com/golang/go/src . `crypto/tls`/.Configscip-go gomod github.com/golang/go/src . `crypto/tls`/Config#{
64 InsecureSkipVerifyscip-go gomod github.com/golang/go/src . `crypto/tls`/Config#InsecureSkipVerify.: true,
65 MinVersionscip-go gomod github.com/golang/go/src . `crypto/tls`/Config#MinVersion.: tlsscip-go gomod github.com/golang/go/src . `crypto/tls`/.VersionTLS12scip-go gomod github.com/golang/go/src . `crypto/tls`/VersionTLS12.,
66 },
67 },
68 }
69 s.Logscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Logger#Log().("Warning: TLS verification is disabled, making connections insecure")
70 }
71 } else {
72 if s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#httpClient. == nil {
73 s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#httpClient. = &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{
74 Timeoutscip-go gomod github.com/golang/go/src . `net/http`/Client#Timeout.: HTTPTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/HTTPTimeout. * timescip-go gomod github.com/golang/go/src . time/.Secondscip-go gomod github.com/golang/go/src . time/Second.,
75 Transportscip-go gomod github.com/golang/go/src . `net/http`/Client#Transport.: &httpscip-go gomod github.com/golang/go/src . `net/http`/.Transportscip-go gomod github.com/golang/go/src . `net/http`/Transport#{
76 TLSClientConfigscip-go gomod github.com/golang/go/src . `net/http`/Transport#TLSClientConfig.: &tlsscip-go gomod github.com/golang/go/src . `crypto/tls`/.Configscip-go gomod github.com/golang/go/src . `crypto/tls`/Config#{MinVersionscip-go gomod github.com/golang/go/src . `crypto/tls`/Config#MinVersion.: tlsscip-go gomod github.com/golang/go/src . `crypto/tls`/.VersionTLS12scip-go gomod github.com/golang/go/src . `crypto/tls`/VersionTLS12.},
77 },
78 }
79 }
80 }
81
82 s.clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#client. = jsonclientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/.NewWithHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewWithHTTPClient().(s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#httpClient.)
83
84 return nil
85 }
86
87 // Send delivers a notification message to ntfy.
88 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#) Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Send().(message string, params *typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#) error {
89 config := s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#Config.
90
91 // Update config with runtime parameters
92 if err := s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#pkr..UpdateConfigFromParamsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/PropKeyResolver#UpdateConfigFromParams().(config, params); err != nil {
93 return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("updating config from params: %w", err)
94 }
95
96 // Execute the API request to send the notification
97 if err := s.sendAPIscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#sendAPI().(config, message); err != nil {
98 return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("failed to send ntfy notification: %w", err)
99 }
100
101 return nil
102 }
103
104 // SetHTTPClient sets a custom HTTP client for the service.
105 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#) SetHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#SetHTTPClient().(client typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient#) {
106 s.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#httpClient. = client
107 if client != nil {
108 s.clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#client. = jsonclientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/.NewWithHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewWithHTTPClient().(client)
109 }
110 }
111
112 // sendAPI sends a notification to the ntfy API.
113 func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#) sendAPIscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#sendAPI().(config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#, message string) error {
114 response := apiResponseErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/apiResponseError#{}
115 request := message
116
117 // Prepare request headers
118 headers := s.clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#client..Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.()
119 if config.Markdownscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Markdown. {
120 headers.Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", "text/markdown")
121 } else {
122 headers.Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", "text/plain; charset=utf-8")
123 }
124
125 headers.Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("User-Agent", "shoutrrr/"+metascip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/internal/meta`/.Versionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/internal/meta`/Version.)
126 addHeaderIfNotEmptyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/addHeaderIfNotEmpty().(&headers, "Title", config.Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Title.)
127 addHeaderIfNotEmptyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/addHeaderIfNotEmpty().(&headers, "Priority", config.Priorityscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Priority..Stringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/priority#String().())
128 addHeaderIfNotEmptyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/addHeaderIfNotEmpty().(&headers, "Tags", stringsscip-go gomod github.com/golang/go/src . strings/.Joinscip-go gomod github.com/golang/go/src . strings/Join().(config.Tagsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Tags., ","))
129 addHeaderIfNotEmptyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/addHeaderIfNotEmpty().(&headers, "Delay", config.Delayscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Delay.)
130 addHeaderIfNotEmptyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/addHeaderIfNotEmpty().(&headers, "Actions", stringsscip-go gomod github.com/golang/go/src . strings/.Joinscip-go gomod github.com/golang/go/src . strings/Join().(config.Actionsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Actions., ";"))
131 addHeaderIfNotEmptyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/addHeaderIfNotEmpty().(&headers, "Click", config.Clickscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Click.)
132 addHeaderIfNotEmptyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/addHeaderIfNotEmpty().(&headers, "Attach", config.Attachscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Attach.)
133 addHeaderIfNotEmptyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/addHeaderIfNotEmpty().(&headers, "X-Icon", config.Iconscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Icon.)
134 addHeaderIfNotEmptyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/addHeaderIfNotEmpty().(&headers, "Filename", config.Filenamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Filename.)
135 addHeaderIfNotEmptyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/addHeaderIfNotEmpty().(&headers, "Email", config.Emailscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Email.)
136
137 if !config.Cachescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Cache. {
138 headers.Addscip-go gomod github.com/golang/go/src . `net/http`/Header#Add().("Cache", "no")
139 }
140
141 if !config.Firebasescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Firebase. {
142 headers.Addscip-go gomod github.com/golang/go/src . `net/http`/Header#Add().("Firebase", "no")
143 }
144
145 // Add Basic Auth header if username or password is provided
146 if config.Usernamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Username. != "" || config.Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Password. != "" {
147 headers.Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().(
148 "Authorization",
149 "Basic "+base64scip-go gomod github.com/golang/go/src . `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src . `encoding/base64`/StdEncoding..EncodeToStringscip-go gomod github.com/golang/go/src . `encoding/base64`/Encoding#EncodeToString().([]byte(config.Usernamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Username.+":"+config.Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#Password.)),
150 )
151 }
152
153 // Send the HTTP request
154 if err := s.clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#client..Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.(config.GetAPIURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Config#GetAPIURL().(), request, &response); err != nil {
155 s.Logfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Logger#Logf().("NTFY API request failed with error: %v", err)
156 // Attempt to parse structured error response from API
157 if s.clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/Service#client..ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#ErrorResponse.(err, &response) {
158 return &response
159 }
160
161 return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("posting to ntfy API: %w", err)
162 }
163
164 s.Logfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Logger#Logf().("NTFY API request succeeded")
165
166 return nil
167 }
168
169 // addHeaderIfNotEmpty adds a header to the request if the value is non-empty.
170 func addHeaderIfNotEmptyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy`/addHeaderIfNotEmpty().(headers *httpscip-go gomod github.com/golang/go/src . `net/http`/.Headerscip-go gomod github.com/golang/go/src . `net/http`/Header#, key, value string) {
171 if value != "" {
172 headers.Addscip-go gomod github.com/golang/go/src . `net/http`/Header#Add().(key, value)
173 }
174 }