aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/url.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2021-10-18 18:22:35 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2021-10-18 18:36:04 +0200
commitf6a8bfcdb31b3a42002e9d1c113bd547ffe5ef29 (patch)
treeab2f77c023bdc7a324f99c190ac063c582c6c7ac /pkg/config/url.go
parentf2996a1cb8eca70c97f5cd847c2c409a67083392 (diff)
downloadfeed2imap-go-f6a8bfcdb31b3a42002e9d1c113bd547ffe5ef29.tar.gz
feed2imap-go-f6a8bfcdb31b3a42002e9d1c113bd547ffe5ef29.tar.bz2
feed2imap-go-f6a8bfcdb31b3a42002e9d1c113bd547ffe5ef29.zip
Improve Url.String()
Diffstat (limited to '')
-rw-r--r--pkg/config/url.go27
1 files changed, 19 insertions, 8 deletions
diff --git a/pkg/config/url.go b/pkg/config/url.go
index 7e91411..4b3abf7 100644
--- a/pkg/config/url.go
+++ b/pkg/config/url.go
@@ -65,18 +65,29 @@ func (u *Url) UnmarshalYAML(value *yaml.Node) (err error) {
}
func (u Url) String() string {
- scheme := u.Scheme + "://"
+ var sb strings.Builder
- var pwd string
- if u.Password != "" {
- pwd = ":******"
+ sb.WriteString(u.Scheme)
+ sb.WriteString("://")
+
+ if u.User != "" {
+ sb.WriteString(u.User)
+ if u.Password != "" {
+ sb.WriteString(":******")
+ }
+ sb.WriteRune('@')
}
- var delim string
- if pwd != "" || u.User != "" {
- delim = "@"
+
+ sb.WriteString(u.HostPort())
+
+ if u.Root != "" {
+ if u.Root[0] != '/' {
+ sb.WriteRune('/')
+ }
+ sb.WriteString(u.Root)
}
- return scheme + u.User + pwd + delim + u.HostPort() + u.Root
+ return sb.String()
}
func (u *Url) HostPort() string {