Skip to content

Commit

Permalink
Don't use strings.Cut
Browse files Browse the repository at this point in the history
Looks like that function was added in go 1.18 but this project is using go 1.16

https://pkg.go.dev/[email protected]#Cut
  • Loading branch information
edwargix committed Sep 17, 2022
1 parent 4840289 commit 3daa468
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion pkg/cmd/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion pkg/services/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3daa468

Please sign in to comment.