| 1 | package wecomscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/ |
| 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/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 11 | ) |
| 12 | |
| 13 | // Config represents the configuration for the WeCom service. |
| 14 | type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config# struct { |
| 15 | Keyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#Key. string `desc:"Bot webhook key" key:"key"` |
| 16 | MentionedListscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#MentionedList. string `desc:"Users to mention (comma-separated)" key:"mentioned_list"` |
| 17 | MentionedMobileListscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#MentionedMobileList. string `desc:"Mobile numbers to mention (comma-separated)" key:"mentioned_mobile_list"` |
| 18 | } |
| 19 | |
| 20 | // Scheme is the identifier for the WeCom service protocol. |
| 21 | const Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Scheme. = "wecom" |
| 22 | |
| 23 | // Error variables for the WeCom service. |
| 24 | var ( |
| 25 | ErrEmptyKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/ErrEmptyKey. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("WeCom webhook key cannot be empty") |
| 26 | ErrInvalidKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/ErrInvalidKey. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("invalid WeCom webhook key format") |
| 27 | ) |
| 28 | |
| 29 | // Enums returns a map of enum formatters (none for this service). |
| 30 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#) Enumsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/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# { |
| 31 | 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#{} |
| 32 | } |
| 33 | |
| 34 | // GetURL constructs a URL from the Config fields. |
| 35 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#) GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#GetURL().() *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 36 | 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) |
| 37 | |
| 38 | return c.getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#getURL().(&resolver) |
| 39 | } |
| 40 | |
| 41 | // SetURL updates the Config from a URL. |
| 42 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#) SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/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 { |
| 43 | 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) |
| 44 | |
| 45 | return c.setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#setURL().(&resolver, serviceURL) |
| 46 | } |
| 47 | |
| 48 | // getURL constructs a URL using the provided resolver. |
| 49 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#) getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#getURL().(_ 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# { |
| 50 | return &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 51 | 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/chat/wecom`/Scheme., |
| 52 | Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: c.Keyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#Key., |
| 53 | ForceQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#ForceQuery.: false, |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // setURL updates the Config from a URL using the provided resolver. |
| 58 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#) setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/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 { |
| 59 | // Handle dummy URL used for documentation generation |
| 60 | if serviceURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().() == "wecom://[email protected]" { |
| 61 | c.Keyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#Key. = "dummy-webhook-key" |
| 62 | |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | // Extract key from host |
| 67 | c.Keyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#Key. = serviceURL.Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host. |
| 68 | |
| 69 | // Validate key format (alphanumeric, hyphens, underscores only) |
| 70 | if c.Keyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#Key. == "" { |
| 71 | return ErrEmptyKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/ErrEmptyKey. |
| 72 | } |
| 73 | |
| 74 | if stringsscip-go gomod github.com/golang/go/src . strings/.ContainsAnyscip-go gomod github.com/golang/go/src . strings/ContainsAny().(c.Keyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#Key., "@!#$%^&*()+=[]{}|\\:;\"'<>?,./") { |
| 75 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%w: %s", ErrInvalidKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/ErrInvalidKey., c.Keyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/wecom`/Config#Key.) |
| 76 | } |
| 77 | |
| 78 | // Handle query parameters |
| 79 | for key, vals := range serviceURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().() { |
| 80 | 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 { |
| 81 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("setting query parameter %q: %w", key, err) |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return nil |
| 86 | } |