| 1 | package mattermostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/ |
| 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 | "stringsscip-go gomod github.com/golang/go/src . strings/" |
| 7 | |
| 8 | "github.com/nicholas-fedor/shoutrrr/pkg/formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/" |
| 9 | "github.com/nicholas-fedor/shoutrrr/pkg/services/standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/" |
| 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 holds all configuration information for the Mattermost service. |
| 14 | type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config# struct { |
| 15 | 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/chat/mattermost`/Config#EnumlessConfig. |
| 16 | |
| 17 | UserNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#UserName. string `desc:"Override webhook user" optional:"" url:"user"` |
| 18 | Iconscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#Icon. string `desc:"Use emoji or URL as icon (based on presence of http(s):// prefix)" optional:"" default:"" key:"icon,icon_emoji,icon_url"` |
| 19 | Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#Title. string `desc:"Notification title, optionally set by the sender" default:"" key:"title"` |
| 20 | Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#Channel. string `desc:"Override webhook channel" optional:"" url:"path2"` |
| 21 | Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#Host. string `desc:"Mattermost server host" url:"host,port"` |
| 22 | Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#Token. string `desc:"Webhook token" url:"path1"` |
| 23 | DisableTLSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#DisableTLS. bool ` default:"No" key:"disabletls"` |
| 24 | } |
| 25 | |
| 26 | // Scheme is the identifying part of this service's configuration URL. |
| 27 | const Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Scheme. = "mattermost" |
| 28 | |
| 29 | // CreateConfigFromURL creates a new Config instance from a URL representation. |
| 30 | func CreateConfigFromURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/CreateConfigFromURL().(serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#) (*Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#, error) { |
| 31 | // Config has embedded EnumlessConfig and URL-tagged fields are set via SetURL |
| 32 | config := &Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#{} |
| 33 | if err := config.SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#SetURL().(serviceURL); err != nil { |
| 34 | return nil, err |
| 35 | } |
| 36 | |
| 37 | return config, nil |
| 38 | } |
| 39 | |
| 40 | // GetURL returns a URL representation of the Config's current field values. |
| 41 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#) GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#GetURL().() *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 42 | 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) |
| 43 | |
| 44 | return c.getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#getURL().(&resolver) // Pass pointer to resolver |
| 45 | } |
| 46 | |
| 47 | // SetURL updates the Config from a URL representation of its field values. |
| 48 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#) SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/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 { |
| 49 | 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) |
| 50 | |
| 51 | return c.setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#setURL().(&resolver, serviceURL) // Pass pointer to resolver |
| 52 | } |
| 53 | |
| 54 | // getURL constructs a URL from the Config's fields using the provided resolver. |
| 55 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#) getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/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# { |
| 56 | paths := []string{"", c.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#Token., c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#Channel.} |
| 57 | if c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#Channel. == "" { |
| 58 | paths = paths[:2] |
| 59 | } |
| 60 | |
| 61 | var user *urlscip-go gomod github.com/golang/go/src . `net/url`/.Userinfoscip-go gomod github.com/golang/go/src . `net/url`/Userinfo# |
| 62 | if c.UserNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#UserName. != "" { |
| 63 | user = urlscip-go gomod github.com/golang/go/src . `net/url`/.Userscip-go gomod github.com/golang/go/src . `net/url`/User().(c.UserNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#UserName.) |
| 64 | } |
| 65 | |
| 66 | // URL is constructed with only the fields needed for service URL representation |
| 67 | return &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 68 | Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User.: user, |
| 69 | 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/chat/mattermost`/Config#Host., |
| 70 | Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.: stringsscip-go gomod github.com/golang/go/src . strings/.Joinscip-go gomod github.com/golang/go/src . strings/Join().(paths, "/"), |
| 71 | 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/mattermost`/Scheme., |
| 72 | ForceQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#ForceQuery.: false, |
| 73 | 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), |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // parsePath extracts Token and Channel from the URL path and validates arguments. |
| 78 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#) parsePathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#parsePath().(serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#) error { |
| 79 | path := stringsscip-go gomod github.com/golang/go/src . strings/.Splitscip-go gomod github.com/golang/go/src . strings/Split().(stringsscip-go gomod github.com/golang/go/src . strings/.Trimscip-go gomod github.com/golang/go/src . strings/Trim().(serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path., "/"), "/") |
| 80 | isDummy := serviceURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().() == "mattermost://[email protected]" |
| 81 | |
| 82 | if !isDummy && (len(path) < 1 || path[0] == "") { |
| 83 | return ErrNotEnoughArgumentsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/ErrNotEnoughArguments. |
| 84 | } |
| 85 | |
| 86 | if len(path) > 0 && path[0] != "" { |
| 87 | c.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#Token. = path[0] |
| 88 | } |
| 89 | |
| 90 | if len(path) > 1 && path[1] != "" { |
| 91 | c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#Channel. = path[1] |
| 92 | } |
| 93 | |
| 94 | return nil |
| 95 | } |
| 96 | |
| 97 | // setURL updates the Config from a URL using the provided resolver. |
| 98 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#) setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/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 { |
| 99 | c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#Host. = serviceURL.Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host. |
| 100 | c.UserNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#UserName. = 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().() |
| 101 | |
| 102 | if err := c.parsePathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/mattermost`/Config#parsePath().(serviceURL); err != nil { |
| 103 | return err |
| 104 | } |
| 105 | |
| 106 | for key, vals := range serviceURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().() { |
| 107 | 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 { |
| 108 | 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) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return nil |
| 113 | } |