Skip to content

Commit 2641e19

Browse files
committed
refactor(workflows): replace manual sort block with slices.Sorted(maps.Keys(...))
1 parent 8b048e5 commit 2641e19

4 files changed

Lines changed: 13 additions & 39 deletions

File tree

internal/workflows/tasks/providers/thand/approvals.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package thand
33
import (
44
"errors"
55
"fmt"
6-
"sort"
6+
"maps"
7+
"slices"
78
"time"
89

910
cloudevents "github.com/cloudevents/sdk-go/v2"
@@ -435,13 +436,7 @@ func (t *thandTask) makeApprovalNotifications(
435436
// In parallel create a notifier for each of the notifiers
436437
// Build notification tasks for each provider
437438
var notifyTasks []notifyTask
438-
providerKeys := make([]string, 0, len(approvalsTask.Notifiers))
439-
for providerKey := range approvalsTask.Notifiers {
440-
providerKeys = append(providerKeys, providerKey)
441-
}
442-
sort.Strings(providerKeys)
443-
444-
for _, providerKey := range providerKeys {
439+
for _, providerKey := range slices.Sorted(maps.Keys(approvalsTask.Notifiers)) {
445440
notifierRequest := approvalsTask.Notifiers[providerKey]
446441
// Create an ApprovalNotifier for each provider
447442
approvalNotifier := NewApprovalsNotifier(
@@ -554,13 +549,7 @@ func (t *thandTask) notifyApprovalRejection(
554549
}
555550

556551
// Send rejection notification using each configured notifier
557-
providerKeys := make([]string, 0, len(approvalsTask.Notifiers))
558-
for providerKey := range approvalsTask.Notifiers {
559-
providerKeys = append(providerKeys, providerKey)
560-
}
561-
sort.Strings(providerKeys)
562-
563-
for _, providerKey := range providerKeys {
552+
for _, providerKey := range slices.Sorted(maps.Keys(approvalsTask.Notifiers)) {
564553
notifierRequest := approvalsTask.Notifiers[providerKey]
565554
// Create a generic notifier for rejection with the approver as recipient
566555
rejectionRequest := thandFunction.NotifierRequest{

internal/workflows/tasks/providers/thand/authorize.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package thand
33
import (
44
"errors"
55
"fmt"
6+
"maps"
67
"net/http"
7-
"sort"
8+
"slices"
89
"sync"
910
"time"
1011

@@ -557,13 +558,7 @@ func (t *thandTask) makeAuthorizationNotifications(
557558

558559
// Build notification tasks for each provider
559560
var notifyTasks []notifyTask
560-
providerKeys := make([]string, 0, len(authorizeTask.Notifiers))
561-
for providerKey := range authorizeTask.Notifiers {
562-
providerKeys = append(providerKeys, providerKey)
563-
}
564-
sort.Strings(providerKeys)
565-
566-
for _, providerKey := range providerKeys {
561+
for _, providerKey := range slices.Sorted(maps.Keys(authorizeTask.Notifiers)) {
567562
notifierRequest := authorizeTask.Notifiers[providerKey]
568563
// Create an AuthorizerNotifier for each provider
569564
authorizeNotifier := NewAuthorizerNotifier(

internal/workflows/tasks/providers/thand/form.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7-
"sort"
7+
"maps"
8+
"slices"
89

910
cloudevents "github.com/cloudevents/sdk-go/v2"
1011
"github.com/serverlessworkflow/sdk-go/v3/model"
@@ -249,13 +250,7 @@ func (t *thandTask) makeFormNotifications(
249250

250251
var notifyTasks []notifyTask
251252

252-
providerKeys := make([]string, 0, len(formTask.Notifiers))
253-
for providerKey := range formTask.Notifiers {
254-
providerKeys = append(providerKeys, providerKey)
255-
}
256-
sort.Strings(providerKeys)
257-
258-
for _, providerKey := range providerKeys {
253+
for _, providerKey := range slices.Sorted(maps.Keys(formTask.Notifiers)) {
259254
notifierRequest := formTask.Notifiers[providerKey]
260255
// Create a FormNotifier for each provider
261256
formNotifier := NewFormNotifier(

internal/workflows/tasks/providers/thand/revoke.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package thand
33
import (
44
"errors"
55
"fmt"
6-
"sort"
6+
"maps"
7+
"slices"
78
"sync"
89
"time"
910

@@ -366,13 +367,7 @@ func (t *thandTask) makeRevocationNotifications(
366367

367368
// Build notification tasks for each provider
368369
var notifyTasks []notifyTask
369-
providerKeys := make([]string, 0, len(revokeTask.Notifiers))
370-
for providerKey := range revokeTask.Notifiers {
371-
providerKeys = append(providerKeys, providerKey)
372-
}
373-
sort.Strings(providerKeys)
374-
375-
for _, providerKey := range providerKeys {
370+
for _, providerKey := range slices.Sorted(maps.Keys(revokeTask.Notifiers)) {
376371
notifierRequest := revokeTask.Notifiers[providerKey]
377372
// Create a RevokeNotifier for each provider
378373
revokeNotifier := NewRevokeNotifier(

0 commit comments

Comments
 (0)