From f195f9aa701a5b673f6bd22ceb5aaa0961612c35 Mon Sep 17 00:00:00 2001 From: David Florness Date: Sat, 17 Sep 2022 15:54:05 -0400 Subject: [PATCH] Don't use strings.Cut Looks like that function was added in go 1.18 but this project is using go 1.17 https://pkg.go.dev/strings@go1.18#Cut Signed-off-by: David Florness --- pkg/api/config.go | 9 ++++++++- pkg/cmd/template.go | 9 ++++++++- pkg/services/matrix.go | 7 ++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pkg/api/config.go b/pkg/api/config.go index e5528fa4..90f651a3 100644 --- a/pkg/api/config.go +++ b/pkg/api/config.go @@ -42,7 +42,14 @@ func (cfg Config) GetGlobalDestinations(labels map[string]string) services.Desti for _, trigger := range triggers { if s.MatchesTrigger(trigger) && s.Selector.Matches(fields.Set(labels)) { for _, recipient := range s.Recipients { - before, after, _ := strings.Cut(recipient, ":") + var before, after string + if i := strings.Index(recipient, ":"); i >= 0 { + before = recipient[:i] + after = recipient[i+1:] + } else { + before = recipient + after = "" + } dest := services.Destination{Service: before} if len(after) > 0 { dest.Recipient = after diff --git a/pkg/cmd/template.go b/pkg/cmd/template.go index d98a7123..0c5437ef 100644 --- a/pkg/cmd/template.go +++ b/pkg/cmd/template.go @@ -62,7 +62,14 @@ func newTemplateNotifyCommand(cmdContext *commandContext) *cobra.Command { } for _, recipient := range recipients { - before, after, _ := strings.Cut(recipient, ":") + var before, after string + if i := strings.Index(recipient, ":"); i >= 0 { + before = recipient[:i] + after = recipient[i+1:] + } else { + before = recipient + after = "" + } dest := services.Destination{Service: before} if len(after) > 0 { dest.Recipient = after diff --git a/pkg/services/matrix.go b/pkg/services/matrix.go index bc7b0a16..22f93456 100644 --- a/pkg/services/matrix.go +++ b/pkg/services/matrix.go @@ -63,7 +63,12 @@ func (s *matrixService) Send(notification Notification, dest Destination) error return fmt.Errorf("couldn't resolve room alias '%s': %w", dest.Recipient, err) } roomID = resp.RoomID - _, serverName, _ = strings.Cut(roomAlias.String(), ":") + roomAliasStr := roomAlias.String() + if i := strings.Index(roomAliasStr, ":"); i >= 0 { + serverName = roomAliasStr[i+1:] + } else { + serverName = "" + } } markdownContent := format.RenderMarkdown(notification.Message, true, true)