forked from gregorynoma/tsbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.go
42 lines (37 loc) · 972 Bytes
/
funcs.go
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
package utils
import (
"fmt"
"time"
)
func IsIn(s string, arr []string) bool {
for _, x := range arr {
if s == x {
return true
}
}
return false
}
// ParseUTCTime parses a string-represented time of the format 2006-01-02T15:04:05Z07:00
func ParseUTCTime(s string) (time.Time, error) {
t, err := time.Parse(time.RFC3339, s)
if err != nil {
return time.Time{}, err
}
return t.UTC(), nil
}
const (
errInvalidGroupsFmt = "incorrect interleaved groups configuration: id %d >= total groups %d"
errTotalGroupsZero = "incorrect interleaved groups configuration: total groups = 0"
)
// ValidateGroups checks validity of combination groupID and totalGroups
func ValidateGroups(groupID, totalGroupsNum uint) error {
if totalGroupsNum == 0 {
// Need at least one group
return fmt.Errorf(errTotalGroupsZero)
}
if groupID >= totalGroupsNum {
// Need reasonable groupID
return fmt.Errorf(errInvalidGroupsFmt, groupID, totalGroupsNum)
}
return nil
}