-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.go
More file actions
54 lines (50 loc) · 1.13 KB
/
helpers.go
File metadata and controls
54 lines (50 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package flashduty
import (
"strconv"
"strings"
)
func parseCommaSeparatedStrings(s string) []string {
if s == "" {
return nil
}
parts := strings.Split(s, ",")
result := make([]string, 0, len(parts))
for _, part := range parts {
part = strings.TrimSpace(part)
if part != "" {
result = append(result, part)
}
}
return result
}
// mergeChannelIDs combines a primary slice with a deprecated singular ChannelID
// field. The slice wins when set; otherwise a non-zero singular value is wrapped
// into a one-element slice. Used to migrate callers from ChannelID to ChannelIDs
// without breaking existing code.
func mergeChannelIDs(channelIDs []int64, channelID int64) []int64 {
if len(channelIDs) > 0 {
return channelIDs
}
if channelID > 0 {
return []int64{channelID}
}
return nil
}
func parseCommaSeparatedInts(s string) []int {
if s == "" {
return nil
}
parts := strings.Split(s, ",")
result := make([]int, 0, len(parts))
for _, part := range parts {
part = strings.TrimSpace(part)
if part == "" {
continue
}
id, err := strconv.Atoi(part)
if err == nil {
result = append(result, id)
}
}
return result
}