| 1 | package matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/ |
| 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/services/standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/" |
| 9 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 10 | ) |
| 11 | |
| 12 | // Config is the configuration for the matrix service. |
| 13 | type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config# struct { |
| 14 | 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/matrix`/Config#EnumlessConfig. |
| 15 | |
| 16 | Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#User. string `desc:"Username or empty when using access token" optional:"" url:"user"` |
| 17 | |
| 18 | Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Password. string `desc:"Password or access token" url:"password"` |
| 19 | DisableTLSscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#DisableTLS. bool ` default:"No" key:"disableTLS"` |
| 20 | Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Host. string ` url:"host"` |
| 21 | Roomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Rooms. []string `desc:"Room aliases, or with ! prefix, room IDs" key:"rooms,room" optional:""` |
| 22 | Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Title. string ` default:"" key:"title"` |
| 23 | } |
| 24 | |
| 25 | // GetURL returns a URL representation of it's current field values. |
| 26 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#) GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#GetURL().() *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 27 | 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) |
| 28 | |
| 29 | return c.getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#getURL().(&resolver) |
| 30 | } |
| 31 | |
| 32 | // SetURL updates a ServiceConfig from a URL representation of it's field values. |
| 33 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#) SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/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 { |
| 34 | 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) |
| 35 | |
| 36 | return c.setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#setURL().(&resolver, serviceURL) |
| 37 | } |
| 38 | |
| 39 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#) getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/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# { |
| 40 | return &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 41 | 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.Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#User., c.Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Password.), |
| 42 | 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/matrix`/Config#Host., |
| 43 | 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/matrix`/Scheme., |
| 44 | ForceQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#ForceQuery.: true, |
| 45 | 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), |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#) setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/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 { |
| 50 | // Skip credential validation and query parameter parsing for dummy URLs |
| 51 | // used in docs generation. Query params (rooms, title, disableTLS) are |
| 52 | // intentionally ignored for dummy.com to avoid validation errors. |
| 53 | if serviceURL.Hostnamescip-go gomod github.com/golang/go/src . `net/url`/URL#Hostname().() == "dummy.com" { |
| 54 | c.Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#User. = 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().() |
| 55 | if password, ok := 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().(); ok { |
| 56 | c.Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Password. = password |
| 57 | } |
| 58 | |
| 59 | c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Host. = serviceURL.Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host. |
| 60 | |
| 61 | return nil |
| 62 | } |
| 63 | |
| 64 | c.Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#User. = 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().() |
| 65 | |
| 66 | password, ok := 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().() |
| 67 | if !ok { |
| 68 | return ErrMissingCredentialsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/ErrMissingCredentials. |
| 69 | } |
| 70 | |
| 71 | c.Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Password. = password |
| 72 | c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Host. = serviceURL.Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host. |
| 73 | |
| 74 | if c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Host. == "" { |
| 75 | return ErrMissingHostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/ErrMissingHost. |
| 76 | } |
| 77 | |
| 78 | for key, vals := range serviceURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().() { |
| 79 | 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 { |
| 80 | 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) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | for r, room := range c.Roomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Rooms. { |
| 85 | // If room does not begin with a '#' let's prepend it |
| 86 | if room != "" && room[0] != '#' && room[0] != '!' { |
| 87 | c.Roomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Rooms.[r] = "#" + room |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | return nil |
| 92 | } |