| 1 | package barkscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/ |
| 2 | |
| 3 | import ( |
| 4 | "errorsscip-go gomod github.com/golang/go/src . errors/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 6 | "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src . strings/" |
| 8 | |
| 9 | "github.com/nicholas-fedor/shoutrrr/pkg/formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/" |
| 10 | "github.com/nicholas-fedor/shoutrrr/pkg/services/standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/" |
| 11 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 12 | ) |
| 13 | |
| 14 | // Config holds configuration settings for the Bark service. |
| 15 | type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config# struct { |
| 16 | standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/.EnumlessConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#EnumlessConfig. |
| 17 | |
| 18 | Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Title. string `default:"" desc:"Notification title, optionally set by the sender" key:"title"` |
| 19 | Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Host. string ` desc:"Server hostname and port" url:"host"` |
| 20 | Pathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Path. string `default:"/" desc:"Server path" url:"path"` |
| 21 | DeviceKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#DeviceKey. string ` desc:"The key for each device" url:"password"` |
| 22 | Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Scheme. string `default:"https" desc:"Server protocol, http or https" key:"scheme"` |
| 23 | Soundscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Sound. string `default:"" desc:"Value from https://github.com/Finb/Bark/tree/master/Sounds" key:"sound"` |
| 24 | Badgescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Badge. int64 `default:"0" desc:"The number displayed next to App icon" key:"badge"` |
| 25 | Iconscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Icon. string `default:"" desc:"An url to the icon, available only on iOS 15 or later" key:"icon"` |
| 26 | Groupscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Group. string `default:"" desc:"The group of the notification" key:"group"` |
| 27 | URLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#URL. string `default:"" desc:"Url that will jump when click notification" key:"url"` |
| 28 | Categoryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Category. string `default:"" desc:"Reserved field, no use yet" key:"category"` |
| 29 | Copyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Copy. string `default:"" desc:"The value to be copied" key:"copy"` |
| 30 | } |
| 31 | |
| 32 | // Scheme is the URL scheme identifier for the Bark service. |
| 33 | const Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Scheme. = "bark" |
| 34 | |
| 35 | // ErrSetQueryFailed indicates a failure to set a configuration value from a query parameter. |
| 36 | var ErrSetQueryFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/ErrSetQueryFailed. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("failed to set query parameter") |
| 37 | |
| 38 | // GetAPIURL constructs the full API URL for a given endpoint. |
| 39 | // The endpoint is appended to the configured host and path. |
| 40 | // |
| 41 | // Parameters: |
| 42 | // - endpoint: The API endpoint to access (e.g., "push", "register"). |
| 43 | // |
| 44 | // Returns: |
| 45 | // - The complete URL string for the API request. |
| 46 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#) GetAPIURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#GetAPIURL().(endpoint string) string { |
| 47 | path := stringsscip-go gomod github.com/golang/go/src . strings/.Builderscip-go gomod github.com/golang/go/src . strings/Builder#{} |
| 48 | if !stringsscip-go gomod github.com/golang/go/src . strings/.HasPrefixscip-go gomod github.com/golang/go/src . strings/HasPrefix().(c.Pathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Path., "/") { |
| 49 | path.WriteBytescip-go gomod github.com/golang/go/src . strings/Builder#WriteByte().('/') |
| 50 | } |
| 51 | |
| 52 | path.WriteStringscip-go gomod github.com/golang/go/src . strings/Builder#WriteString().(c.Pathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Path.) |
| 53 | |
| 54 | if !stringsscip-go gomod github.com/golang/go/src . strings/.HasSuffixscip-go gomod github.com/golang/go/src . strings/HasSuffix().(path.Stringscip-go gomod github.com/golang/go/src . strings/Builder#String().(), "/") { |
| 55 | path.WriteBytescip-go gomod github.com/golang/go/src . strings/Builder#WriteByte().('/') |
| 56 | } |
| 57 | |
| 58 | path.WriteStringscip-go gomod github.com/golang/go/src . strings/Builder#WriteString().(endpoint) |
| 59 | |
| 60 | apiURL := urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 61 | Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme.: c.Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Scheme., |
| 62 | Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Host., |
| 63 | Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.: path.Stringscip-go gomod github.com/golang/go/src . strings/Builder#String().(), |
| 64 | } |
| 65 | |
| 66 | return apiURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().() |
| 67 | } |
| 68 | |
| 69 | // GetURL returns a URL representation of the current configuration. |
| 70 | // This URL can be used to share or persist the service configuration. |
| 71 | // |
| 72 | // Returns: |
| 73 | // - A URL struct containing the configuration as query parameters. |
| 74 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#) GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#GetURL().() *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 75 | resolver := 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().(c) |
| 76 | |
| 77 | return c.getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#getURL().(&resolver) |
| 78 | } |
| 79 | |
| 80 | // SetURL updates the configuration from a URL representation. |
| 81 | // The URL should contain the device key as the password and optional query parameters. |
| 82 | // |
| 83 | // Parameters: |
| 84 | // - serviceURL: URL containing the service configuration. |
| 85 | // |
| 86 | // Returns: |
| 87 | // - An error if the URL is invalid or missing required parameters. |
| 88 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#) SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#SetURL().(serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#) error { |
| 89 | resolver := 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().(c) |
| 90 | |
| 91 | return c.setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#setURL().(&resolver, serviceURL) |
| 92 | } |
| 93 | |
| 94 | // getURL generates a URL representation using the provided resolver. |
| 95 | // This internal method handles the actual URL construction logic. |
| 96 | // |
| 97 | // Parameters: |
| 98 | // - resolver: Configuration query resolver for building URL parameters. |
| 99 | // |
| 100 | // Returns: |
| 101 | // - A URL struct with embedded credentials and query parameters. |
| 102 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#) getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#getURL().(resolver typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.ConfigQueryResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ConfigQueryResolver#) *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 103 | return &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 104 | Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User.: urlscip-go gomod github.com/golang/go/src . `net/url`/.UserPasswordscip-go gomod github.com/golang/go/src . `net/url`/UserPassword().("", c.DeviceKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#DeviceKey.), |
| 105 | Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Host., |
| 106 | Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme.: Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Scheme., |
| 107 | ForceQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#ForceQuery.: true, |
| 108 | Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.: c.Pathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Path., |
| 109 | RawQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#RawQuery.: formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.BuildQueryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/BuildQuery().(resolver), |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // setURL parses a service URL and updates the configuration accordingly. |
| 114 | // It extracts the device key from the password field and host from the URL. |
| 115 | // |
| 116 | // Parameters: |
| 117 | // - resolver: Configuration query resolver for setting query parameters. |
| 118 | // - serviceURL: URL containing the service configuration. |
| 119 | // |
| 120 | // Returns: |
| 121 | // - An error if required fields are missing or query parameters are invalid. |
| 122 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#) setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#setURL().(resolver typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.ConfigQueryResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ConfigQueryResolver#, serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#) error { |
| 123 | password, _ := serviceURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User..Passwordscip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Password().() |
| 124 | c.DeviceKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#DeviceKey. = password |
| 125 | c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Host. = serviceURL.Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host. |
| 126 | c.Pathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Path. = serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path. |
| 127 | |
| 128 | // Skip validation for dummy URLs used in docs generation |
| 129 | if serviceURL.Hostnamescip-go gomod github.com/golang/go/src . `net/url`/URL#Hostname().() == "dummy.com" { |
| 130 | return nil |
| 131 | } |
| 132 | |
| 133 | // Validate required fields |
| 134 | if c.DeviceKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#DeviceKey. == "" { |
| 135 | return ErrMissingDeviceKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/ErrMissingDeviceKey. |
| 136 | } |
| 137 | |
| 138 | if c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/Config#Host. == "" { |
| 139 | return ErrMissingHostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/ErrMissingHost. |
| 140 | } |
| 141 | |
| 142 | for key, vals := range serviceURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().() { |
| 143 | if err := resolver.Setscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ConfigQueryResolver#Set.(key, vals[0]); err != nil { |
| 144 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%w '%s': %w", ErrSetQueryFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/bark`/ErrSetQueryFailed., key, err) |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | return nil |
| 149 | } |