| 1 | package signalgridscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 5 | "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 6 | |
| 7 | "github.com/nicholas-fedor/shoutrrr/pkg/formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/" |
| 8 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 9 | ) |
| 10 | |
| 11 | // Config holds settings for the Signalgrid notification service. |
| 12 | type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config# struct { |
| 13 | // ClientKey is the Signalgrid client key used to authenticate Push API requests. |
| 14 | ClientKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#ClientKey. string `desc:"Signalgrid client key" url:"user"` |
| 15 | // Channel is the destination channel token. |
| 16 | Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#Channel. string `desc:"Signalgrid channel token" url:"host"` |
| 17 | // Title is an optional notification title. It is omitted from the API request when empty. |
| 18 | Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#Title. string `desc:"Notification title" key:"title" optional:""` |
| 19 | // Type is the visual severity of the notification. Default: INFO. |
| 20 | Typescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#Type. notificationTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/notificationType# `default:"INFO" desc:"Notification severity (CRIT, WARN, INFO, SUCCESS)" key:"type"` |
| 21 | // Critical delivers the notification as a critical alert when true. |
| 22 | Criticalscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#Critical. bool `default:"No" desc:"Deliver as a critical alert" key:"critical"` |
| 23 | } |
| 24 | |
| 25 | const ( |
| 26 | // Scheme identifies this service in configuration URLs. |
| 27 | Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Scheme. = "signalgrid" |
| 28 | |
| 29 | // dummyServiceURL is the placeholder URL used by documentation generation. |
| 30 | dummyServiceURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/dummyServiceURL. = "signalgrid://[email protected]" |
| 31 | ) |
| 32 | |
| 33 | // Enums returns the fields that use an EnumFormatter for their values. |
| 34 | // |
| 35 | // Returns: |
| 36 | // - A map of config field names to their enum formatters. |
| 37 | func (*Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#) Enumsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#Enums().() map[string]typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.EnumFormatterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/EnumFormatter# { |
| 38 | return map[string]typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.EnumFormatterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/EnumFormatter#{ |
| 39 | "Type": NotificationTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/NotificationType..Enumscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/notificationTypeVals#Enum., |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // GetURL returns a URL representation of the current configuration. |
| 44 | // |
| 45 | // Returns: |
| 46 | // - The service URL encoding the current field values. |
| 47 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#) GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#GetURL().() *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 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.getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#getURL().(&resolver) |
| 51 | } |
| 52 | |
| 53 | // SetURL updates the configuration from a URL representation. |
| 54 | // |
| 55 | // Parameters: |
| 56 | // - serviceURL: The service URL to parse. |
| 57 | // |
| 58 | // Returns: |
| 59 | // - An error if the URL is invalid or required fields are missing. |
| 60 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#) SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/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 { |
| 61 | 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) |
| 62 | |
| 63 | return c.setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#setURL().(&resolver, serviceURL) |
| 64 | } |
| 65 | |
| 66 | // getURL constructs a service URL from the current configuration. |
| 67 | // |
| 68 | // Parameters: |
| 69 | // - resolver: Resolver used to encode query parameters from config fields. |
| 70 | // |
| 71 | // Returns: |
| 72 | // - The service URL with the client key as userinfo and the channel as host. |
| 73 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#) getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/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# { |
| 74 | return &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 75 | 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/signalgrid`/Scheme., |
| 76 | Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User.: urlscip-go gomod github.com/golang/go/src . `net/url`/.Userscip-go gomod github.com/golang/go/src . `net/url`/User().(c.ClientKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#ClientKey.), |
| 77 | Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#Channel., |
| 78 | 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), |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // setURL updates the configuration from a service URL. |
| 83 | // |
| 84 | // Parameters: |
| 85 | // - resolver: Resolver used to apply query parameters to config fields. |
| 86 | // - serviceURL: The service URL to parse. |
| 87 | // |
| 88 | // Returns: |
| 89 | // - An error if a query parameter is invalid or required fields are missing. |
| 90 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#) setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/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 { |
| 91 | isDummy := serviceURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().() == dummyServiceURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/dummyServiceURL. |
| 92 | |
| 93 | if serviceURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User. != nil { |
| 94 | c.ClientKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#ClientKey. = serviceURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User..Usernamescip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Username().() |
| 95 | } else { |
| 96 | c.ClientKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#ClientKey. = "" |
| 97 | } |
| 98 | |
| 99 | c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#Channel. = serviceURL.Hostnamescip-go gomod github.com/golang/go/src . `net/url`/URL#Hostname().() |
| 100 | |
| 101 | for key, vals := range serviceURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().() { |
| 102 | if len(vals) == 0 { |
| 103 | continue |
| 104 | } |
| 105 | |
| 106 | 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 { |
| 107 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("setting query parameter %q to %q: %w", key, vals[0], err) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | if isDummy { |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | if c.ClientKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#ClientKey. == "" { |
| 116 | return ErrClientKeyMissingscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/ErrClientKeyMissing. |
| 117 | } |
| 118 | |
| 119 | if c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/Config#Channel. == "" { |
| 120 | return ErrChannelMissingscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/signalgrid`/ErrChannelMissing. |
| 121 | } |
| 122 | |
| 123 | return nil |
| 124 | } |