| 1 | package barkscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src . bytes/" |
| 5 | "contextscip-go gomod github.com/golang/go/src . context/" |
| 6 | "encoding/jsonscip-go gomod github.com/golang/go/src . `encoding/json`/" |
| 7 | "errorsscip-go gomod github.com/golang/go/src . errors/" |
| 8 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 9 | "net/httpscip-go gomod github.com/golang/go/src . `net/http`/" |
| 10 | "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 11 | "timescip-go gomod github.com/golang/go/src . time/" |
| 12 | |
| 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 | // HTTPClient defines the interface for HTTP operations required by the Bark service. |
| 20 | // This interface allows for dependency injection of HTTP clients for testing purposes. |
| 21 | type HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/HTTPClient# interface { |
| 22 | Doscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/HTTPClient#Do.(req *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) (*httpscip-go gomod github.com/golang/go/src . `net/http`/.Responsescip-go gomod github.com/golang/go/src . `net/http`/Response#, error) |
| 23 | } |
| 24 | |
| 25 | // DefaultHTTPClient is the default HTTP client implementation used when no |
| 26 | // custom client is provided. It uses a reasonable timeout to prevent hanging requests. |
| 27 | type DefaultHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/DefaultHTTPClient# struct { |
| 28 | clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/DefaultHTTPClient#client. *httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client# |
| 29 | } |
| 30 | |
| 31 | // Service sends push notifications to Bark-enabled iOS devices. |
| 32 | type Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service# struct { |
| 33 | 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/bark`/Service#Standard. |
| 34 | |
| 35 | Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#Config. *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config# |
| 36 | pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/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# |
| 37 | HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#HTTPClient. HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/HTTPClient# |
| 38 | } |
| 39 | |
| 40 | // defaultHTTPTimeout is the default timeout for HTTP requests. |
| 41 | const defaultHTTPTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/defaultHTTPTimeout. = 30 * timescip-go gomod github.com/golang/go/src . time/.Secondscip-go gomod github.com/golang/go/src . time/Second. |
| 42 | |
| 43 | // NewDefaultHTTPClient creates a new HTTP client with default timeout settings. |
| 44 | // |
| 45 | // Returns: |
| 46 | // - A configured DefaultHTTPClient instance ready for use. |
| 47 | func NewDefaultHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/NewDefaultHTTPClient().() *DefaultHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/DefaultHTTPClient# { |
| 48 | return &DefaultHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/DefaultHTTPClient#{ |
| 49 | clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/DefaultHTTPClient#client.: &httpscip-go gomod github.com/golang/go/src . `net/http`/.Clientscip-go gomod github.com/golang/go/src . `net/http`/Client#{ |
| 50 | Timeoutscip-go gomod github.com/golang/go/src . `net/http`/Client#Timeout.: defaultHTTPTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/defaultHTTPTimeout., |
| 51 | }, |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // Do executes the HTTP request and returns the response. |
| 56 | // |
| 57 | // Parameters: |
| 58 | // - req: The HTTP request to execute. |
| 59 | // |
| 60 | // Returns: |
| 61 | // - The HTTP response from the server. |
| 62 | // - An error if the request fails. |
| 63 | func (c *DefaultHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/DefaultHTTPClient#) Doscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/DefaultHTTPClient#Do().(req *httpscip-go gomod github.com/golang/go/src . `net/http`/.Requestscip-go gomod github.com/golang/go/src . `net/http`/Request#) (*httpscip-go gomod github.com/golang/go/src . `net/http`/.Responsescip-go gomod github.com/golang/go/src . `net/http`/Response#, error) { |
| 64 | resp, err := c.clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/DefaultHTTPClient#client..Doscip-go gomod github.com/golang/go/src . `net/http`/Client#Do().(req) |
| 65 | if err != nil { |
| 66 | return resp, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("executing HTTP request: %w", err) |
| 67 | } |
| 68 | |
| 69 | return resp, nil |
| 70 | } |
| 71 | |
| 72 | // GetID returns the scheme identifier for the Bark service. |
| 73 | // |
| 74 | // Returns: |
| 75 | // - The string "bark" representing this notification service. |
| 76 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#) GetIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#GetID().() string { |
| 77 | return Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Scheme. |
| 78 | } |
| 79 | |
| 80 | // Initialize sets up the Bark service with configuration from the provided URL. |
| 81 | // |
| 82 | // Parameters: |
| 83 | // - serviceURL: URL containing configuration for the Bark service. |
| 84 | // - logger: Standard logger for output messages. |
| 85 | // |
| 86 | // Returns: |
| 87 | // - An error if initialization fails. |
| 88 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#) Initializescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/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 { |
| 89 | s.SetLoggerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Logger#SetLogger().(logger) |
| 90 | s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#Config. = &Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#{} |
| 91 | |
| 92 | s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/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/bark`/Service#Config.) |
| 93 | if s.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#HTTPClient. == nil { |
| 94 | s.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#HTTPClient. = NewDefaultHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/NewDefaultHTTPClient().() |
| 95 | } |
| 96 | |
| 97 | if err := s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/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/bark`/Service#Config.); err != nil { |
| 98 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("setting default properties: %w", err) |
| 99 | } |
| 100 | |
| 101 | return s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#Config..setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#setURL().(&s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#pkr., serviceURL) |
| 102 | } |
| 103 | |
| 104 | // Send transmits a notification message to the Bark server. |
| 105 | // |
| 106 | // Parameters: |
| 107 | // - message: The notification body text to send. |
| 108 | // - params: Additional parameters for notification customization. |
| 109 | // |
| 110 | // Returns: |
| 111 | // - An error if the notification fails to send. |
| 112 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#) Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/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 { |
| 113 | config := s.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#Config. |
| 114 | |
| 115 | if err := s.pkrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#pkr..UpdateConfigFromParamsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/PropKeyResolver#UpdateConfigFromParams().(config, params); err != nil { |
| 116 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%w: %w", ErrUpdateParamsFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/ErrUpdateParamsFailed., err) |
| 117 | } |
| 118 | |
| 119 | if err := s.sendAPIscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#sendAPI().(config, message); err != nil { |
| 120 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("failed to send bark notification: %w", err) |
| 121 | } |
| 122 | |
| 123 | return nil |
| 124 | } |
| 125 | |
| 126 | // SendItems converts message items to plain text and sends as a notification. |
| 127 | // This method handles rich message items by extracting plain text content. |
| 128 | // |
| 129 | // Parameters: |
| 130 | // - items: Slice of message items to send. |
| 131 | // - params: Additional parameters for notification customization. |
| 132 | // |
| 133 | // Returns: |
| 134 | // - An error if the notification fails to send. |
| 135 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#) SendItemsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#SendItems().(items []typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.MessageItemscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/MessageItem#, 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 { |
| 136 | // Convert message items to plain text |
| 137 | message := typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.ItemsToPlainscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ItemsToPlain().(items) |
| 138 | |
| 139 | return s.Sendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#Send().(message, params) |
| 140 | } |
| 141 | |
| 142 | // SetHTTPClient sets a custom HTTP client for the service. |
| 143 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#) SetHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/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#) { |
| 144 | if client == nil { |
| 145 | s.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#HTTPClient. = NewDefaultHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/NewDefaultHTTPClient().() |
| 146 | |
| 147 | return |
| 148 | } |
| 149 | |
| 150 | s.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#HTTPClient. = client |
| 151 | } |
| 152 | |
| 153 | // sendAPI sends a notification to the Bark server using the configured endpoint. |
| 154 | // This method handles JSON serialization, HTTP request creation, and response parsing. |
| 155 | // |
| 156 | // Parameters: |
| 157 | // - config: The Bark service configuration containing API settings. |
| 158 | // - message: The notification body text to send. |
| 159 | // |
| 160 | // Returns: |
| 161 | // - An error if the API request fails. |
| 162 | func (s *Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#) sendAPIscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#sendAPI().(config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#, message string) error { |
| 163 | // Use background context for the request - services can add context support |
| 164 | // by wrapping this method or using a custom HTTP client |
| 165 | ctx := contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().() |
| 166 | |
| 167 | response := APIResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/APIResponse#{} |
| 168 | request := PushPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/PushPayload#{ |
| 169 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/PushPayload#Body.: message, |
| 170 | DeviceKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/PushPayload#DeviceKey.: config.DeviceKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#DeviceKey., |
| 171 | Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/PushPayload#Title.: config.Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Title., |
| 172 | Categoryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/PushPayload#Category.: config.Categoryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Category., |
| 173 | Copyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/PushPayload#Copy.: config.Copyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Copy., |
| 174 | Soundscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/PushPayload#Sound.: config.Soundscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Sound., |
| 175 | Groupscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/PushPayload#Group.: config.Groupscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Group., |
| 176 | Badgescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/PushPayload#Badge.: &config.Badgescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Badge., |
| 177 | Iconscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/PushPayload#Icon.: config.Iconscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Icon., |
| 178 | URLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/PushPayload#URL.: config.URLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#URL., |
| 179 | } |
| 180 | |
| 181 | requestBody, err := jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src . `encoding/json`/Marshal().(request) |
| 182 | if err != nil { |
| 183 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("marshaling request to JSON: %w", err) |
| 184 | } |
| 185 | |
| 186 | apiURL := config.GetAPIURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#GetAPIURL().("push") |
| 187 | |
| 188 | httpReq, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().(ctx, httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodPostscip-go gomod github.com/golang/go/src . `net/http`/MethodPost., apiURL, bytesscip-go gomod github.com/golang/go/src . bytes/.NewReaderscip-go gomod github.com/golang/go/src . bytes/NewReader().(requestBody)) |
| 189 | if err != nil { |
| 190 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("creating request: %w", err) |
| 191 | } |
| 192 | |
| 193 | httpReq.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().("Content-Type", "application/json") |
| 194 | |
| 195 | httpResp, err := s.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Service#HTTPClient..Doscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/HTTPClient#Do.(httpReq) |
| 196 | if err != nil { |
| 197 | var jsonErr jsonclientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/.Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 198 | if errorsscip-go gomod github.com/golang/go/src . errors/.Asscip-go gomod github.com/golang/go/src . errors/As().(err, &jsonErr) { |
| 199 | if jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src . `encoding/json`/Unmarshal().([]byte(jsonErr.Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.), &response) == nil { |
| 200 | return &response |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%w: %w", ErrFailedAPIRequestscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/ErrFailedAPIRequest., err) |
| 205 | } |
| 206 | |
| 207 | defer func() { _ = httpResp.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 208 | |
| 209 | if err := jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.NewDecoderscip-go gomod github.com/golang/go/src . `encoding/json`/NewDecoder().(httpResp.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body.).Decodescip-go gomod github.com/golang/go/src . `encoding/json`/Decoder#Decode().(&response); err != nil { |
| 210 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("decoding response: %w", err) |
| 211 | } |
| 212 | |
| 213 | if response.Codescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/APIResponse#Code. != httpscip-go gomod github.com/golang/go/src . `net/http`/.StatusOKscip-go gomod github.com/golang/go/src . `net/http`/StatusOK. { |
| 214 | if response.Messagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/APIResponse#Message. != "" { |
| 215 | return &response |
| 216 | } |
| 217 | |
| 218 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%w: %d", ErrUnexpectedStatusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/ErrUnexpectedStatus., response.Codescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/APIResponse#Code.) |
| 219 | } |
| 220 | |
| 221 | return nil |
| 222 | } |