Debian Codegraph @

pkg/services/chat/rocketchat/rocketchat_config.go

raw symbols SCIP
1 package rocketchatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/
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/services/standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/"
9 )
10
11 // Config holds the configuration for the Rocket.Chat service.
12 type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config# struct {
13 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/rocketchat`/Config#EnumlessConfig.
14
15 // UserName is the username to display for the message (optional).
16 UserNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#UserName. string `optional:"" url:"user"`
17 // Host is the Rocket.Chat server hostname (required).
18 Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Host. string `url:"host"`
19 // Port is the Rocket.Chat server port (optional).
20 Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Port. string `url:"port"`
21 // TokenA is the first part of the webhook token (required).
22 TokenAscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#TokenA. string `url:"path1"`
23 // Channel is the target channel or user (optional, can include # for channels or @ for users).
24 Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Channel. string `url:"path3"`
25 // TokenB is the second part of the webhook token (required).
26 TokenBscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#TokenB. string `url:"path2"`
27 }
28
29 // Scheme is the identifying part of this service's configuration URL.
30 const Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Scheme. = "rocketchat"
31
32 // Constants for URL path parsing and validation.
33 const (
34 // MinPathParts is the minimum number of path parts required (including empty first slash).
35 MinPathPartsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/MinPathParts. = 3
36 // TokenBIndex is the index for TokenB in the URL path.
37 TokenBIndexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/TokenBIndex. = 2
38 // ChannelIndex is the index for Channel in the URL path.
39 ChannelIndexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/ChannelIndex. = 3
40 )
41
42 // GetURL returns a URL representation of the Config's current field values.
43 //
44 // Returns:
45 // - A pointer to a url.URL struct representing the current configuration
46 func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#) GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#GetURL().() *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# {
47 host := c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Host.
48 if c.Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Port. != "" {
49 host = fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("%s:%s", c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Host., c.Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Port.)
50 }
51
52 serviceURL := &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{
53 Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: host,
54 Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.: fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("%s/%s", c.TokenAscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#TokenA., c.TokenBscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#TokenB.),
55 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/rocketchat`/Scheme.,
56 ForceQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#ForceQuery.: false,
57 }
58
59 return serviceURL
60 }
61
62 // SetURL updates the Config from a URL representation of its field values.
63 //
64 // Params:
65 // - serviceURL: The URL to parse and extract configuration from
66 //
67 // Returns:
68 // - error: An error if the URL is invalid or missing required components
69 func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#) SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/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 {
70 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().()
71 host := serviceURL.Hostnamescip-go gomod github.com/golang/go/src . `net/url`/URL#Hostname().()
72
73 path := stringsscip-go gomod github.com/golang/go/src . strings/.Splitscip-go gomod github.com/golang/go/src . strings/Split().(serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path., "/")
74 if serviceURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().() != "rocketchat://[email protected]" {
75 if len(path) < MinPathPartsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/MinPathParts. {
76 return ErrNotEnoughArgumentsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/ErrNotEnoughArguments.
77 }
78 }
79
80 c.Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Port. = serviceURL.Portscip-go gomod github.com/golang/go/src . `net/url`/URL#Port().()
81 c.UserNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#UserName. = userName
82 c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Host. = host
83
84 if len(path) > 1 {
85 c.TokenAscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#TokenA. = path[1]
86 }
87
88 if len(path) > TokenBIndexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/TokenBIndex. {
89 c.TokenBscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#TokenB. = path[TokenBIndexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/TokenBIndex.]
90 }
91
92 if len(path) > ChannelIndexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/ChannelIndex. {
93 switch {
94 case serviceURL.Fragmentscip-go gomod github.com/golang/go/src . `net/url`/URL#Fragment. != "":
95 c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Channel. = "#" + serviceURL.Fragmentscip-go gomod github.com/golang/go/src . `net/url`/URL#Fragment.
96 case !stringsscip-go gomod github.com/golang/go/src . strings/.HasPrefixscip-go gomod github.com/golang/go/src . strings/HasPrefix().(path[ChannelIndexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/ChannelIndex.], "@"):
97 c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Channel. = "#" + path[ChannelIndexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/ChannelIndex.]
98 default:
99 c.Channelscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/Config#Channel. = path[ChannelIndexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/rocketchat`/ChannelIndex.]
100 }
101 }
102
103 return nil
104 }