| 1 | package gotifyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/jsonscip-go gomod github.com/golang/go/src . `encoding/json`/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 6 | "logscip-go gomod github.com/golang/go/src . log/" |
| 7 | "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 8 | "stringsscip-go gomod github.com/golang/go/src . strings/" |
| 9 | |
| 10 | "github.com/nicholas-fedor/shoutrrr/pkg/formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/" |
| 11 | "github.com/nicholas-fedor/shoutrrr/pkg/services/standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/" |
| 12 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 13 | ) |
| 14 | |
| 15 | // Config holds settings for the Gotify notification service. |
| 16 | // This struct contains all configuration parameters needed to connect to and authenticate |
| 17 | // with a Gotify server, including connection details, authentication credentials, |
| 18 | // notification defaults, and additional metadata. |
| 19 | type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config# struct { |
| 20 | 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/gotify`/Config#EnumlessConfig. // Embeds standard configuration functionality without enum handling |
| 21 | |
| 22 | Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Token. string `desc:"Application token" required:"" url:"path2"` // Gotify application token for authentication (must be 15 chars starting with 'A') |
| 23 | Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Host. string `desc:"Server hostname (and optionally port)" required:"" url:"host,port"` // Gotify server hostname and optional port number |
| 24 | Pathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Path. string `desc:"Server subpath" url:"path1" optional:""` // Optional subpath for Gotify installation (e.g., "/gotify") |
| 25 | Priorityscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Priority. int ` default:"0" key:"priority"` // Notification priority level (-2 to 10, where higher numbers are more important; negative values have special meanings in some clients) |
| 26 | Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Title. string ` default:"Shoutrrr notification" key:"title"` // Default notification title when none provided |
| 27 | DisableTLSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#DisableTLS. bool ` default:"No" key:"disabletls"` // Disable TLS in URL scheme only (use HTTP instead of HTTPS) |
| 28 | InsecureSkipVerifyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#InsecureSkipVerify. bool ` default:"No" key:"insecureskipverify"` // Skip TLS certificate verification (insecure, use with caution) |
| 29 | UseHeaderscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#UseHeader. bool `desc:"Enable header-based authentication" default:"No" key:"useheader"` // Send token in X-Gotify-Key header instead of URL query parameter |
| 30 | Datescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Date. string ` default:"" key:"date"` // Optional custom timestamp in ISO 8601 format for the notification |
| 31 | Extrasscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Extras. map[string]any // Additional extras parsed from JSON - custom key-value pairs sent with notifications |
| 32 | } |
| 33 | |
| 34 | // Scheme identifies this service in configuration URLs. |
| 35 | const ( |
| 36 | Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Scheme. = "gotify" |
| 37 | ) |
| 38 | |
| 39 | // GetURL returns a URL representation of the current configuration. |
| 40 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#) GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#GetURL().() *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 41 | 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) |
| 42 | |
| 43 | return c.getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#getURL().(&resolver) |
| 44 | } |
| 45 | |
| 46 | // SetURL updates the configuration from a URL representation. |
| 47 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#) SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/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 { |
| 48 | 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) |
| 49 | |
| 50 | return c.setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#setURL().(&resolver, serviceURL) |
| 51 | } |
| 52 | |
| 53 | // getURL generates a URL from the current configuration values. |
| 54 | // This internal method constructs a URL representation of the configuration, |
| 55 | // including all settings as query parameters and extras as JSON in the query string. |
| 56 | // Used for serialization and URL reconstruction. |
| 57 | // Parameters: |
| 58 | // - resolver: Configuration resolver for building query parameters from config fields |
| 59 | // |
| 60 | // Returns: *url.URL containing the complete configuration as a URL. |
| 61 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#) getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/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# { |
| 62 | // Build base query string from configuration fields using the resolver |
| 63 | query := 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) |
| 64 | |
| 65 | // Handle extras serialization if present |
| 66 | if c.Extrasscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Extras. != nil { |
| 67 | // Marshal extras map to JSON string |
| 68 | extrasJSON, err := jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src . `encoding/json`/Marshal().(c.Extrasscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Extras.) |
| 69 | if err != nil { |
| 70 | // Skip adding extras when Extras cannot be serialized |
| 71 | logscip-go gomod github.com/golang/go/src . log/.Printfscip-go gomod github.com/golang/go/src . log/Printf().("Failed to marshal Extras %v: %v, skipping extras", c.Extrasscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Extras., err) |
| 72 | } else { |
| 73 | // Append extras to query string with proper URL encoding |
| 74 | if query != "" { |
| 75 | query += "&" |
| 76 | } |
| 77 | |
| 78 | query += "extras=" + urlscip-go gomod github.com/golang/go/src . `net/url`/.QueryEscapescip-go gomod github.com/golang/go/src . `net/url`/QueryEscape().(string(extrasJSON)) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // Construct and return the complete URL |
| 83 | return &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 84 | 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/gotify`/Config#Host., // Server hostname and port |
| 85 | 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/gotify`/Scheme., // URL scheme (gotify) |
| 86 | ForceQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#ForceQuery.: false, // Don't force query string presence |
| 87 | 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/gotify`/Config#Path. + c.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Token., // Path with token appended |
| 88 | RawQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#RawQuery.: query, // Query parameters including extras |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // processQueryParameters processes query parameters from URL. |
| 93 | // This function handles both standard configuration parameters and the special 'extras' |
| 94 | // JSON parameter, setting appropriate config fields through the resolver or direct assignment. |
| 95 | // Parameters: |
| 96 | // - resolver: Configuration resolver for setting standard config properties |
| 97 | // - query: URL query parameters to process |
| 98 | // |
| 99 | // Returns: error if parameter parsing or setting fails. |
| 100 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#) processQueryParametersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#processQueryParameters().( |
| 101 | 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#, |
| 102 | query urlscip-go gomod github.com/golang/go/src . `net/url`/.Valuesscip-go gomod github.com/golang/go/src . `net/url`/Values#, |
| 103 | ) error { |
| 104 | // Iterate through all query parameters |
| 105 | for key := range query { |
| 106 | if key == "extras" { |
| 107 | // Special handling for extras JSON parameter |
| 108 | if query.Getscip-go gomod github.com/golang/go/src . `net/url`/Values#Get().(key) != "" { |
| 109 | // Initialize extras map |
| 110 | c.Extrasscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Extras. = make(map[string]any) |
| 111 | // Parse JSON string into map |
| 112 | if err := jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src . `encoding/json`/Unmarshal().([]byte(query.Getscip-go gomod github.com/golang/go/src . `net/url`/Values#Get().(key)), &c.Extrasscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Extras.); err != nil { |
| 113 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%w", ErrExtrasParseFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/ErrExtrasParseFailed.) |
| 114 | } |
| 115 | } |
| 116 | } else { |
| 117 | // Standard parameter handling through resolver |
| 118 | if err := resolver.Setscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ConfigQueryResolver#Set.(key, query.Getscip-go gomod github.com/golang/go/src . `net/url`/Values#Get().(key)); err != nil { |
| 119 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%w", ErrConfigPropertyFailedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/ErrConfigPropertyFailed.) |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return nil |
| 125 | } |
| 126 | |
| 127 | // setURL updates the configuration from a URL representation. |
| 128 | // This internal method parses a URL and extracts configuration values including |
| 129 | // host, path, token, and query parameters, populating the config struct fields. |
| 130 | // Used for deserialization from URL format. |
| 131 | // Parameters: |
| 132 | // - resolver: Configuration resolver for setting config fields from query parameters |
| 133 | // - url: The URL to parse configuration values from |
| 134 | // |
| 135 | // Returns: error if URL parsing or parameter processing fails. |
| 136 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#) setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/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 { |
| 137 | // Extract and clean the path from the URL |
| 138 | path := serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path. |
| 139 | if path != "" && path[len(path)-1] == '/' { |
| 140 | path = path[:len(path)-1] // Remove trailing slash if present |
| 141 | } |
| 142 | |
| 143 | // Find the last slash to separate path from token |
| 144 | tokenIndex := stringsscip-go gomod github.com/golang/go/src . strings/.LastIndexscip-go gomod github.com/golang/go/src . strings/LastIndex().(path, "/") + 1 |
| 145 | |
| 146 | // Extract path component (everything before the token) |
| 147 | c.Pathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Path. = path[:tokenIndex] |
| 148 | if c.Pathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Path. == "/" { |
| 149 | c.Pathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Path. = c.Pathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Path.[1:] // Remove leading slash to normalize empty path |
| 150 | } |
| 151 | |
| 152 | // Set host and token from URL components |
| 153 | c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Host. = serviceURL.Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host. |
| 154 | c.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#Token. = path[tokenIndex:] |
| 155 | |
| 156 | // Process query parameters to set remaining configuration fields |
| 157 | if err := c.processQueryParametersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/gotify`/Config#processQueryParameters().(resolver, serviceURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().()); err != nil { |
| 158 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("failed to process query parameters: %w", err) |
| 159 | } |
| 160 | |
| 161 | return nil |
| 162 | } |