-
Notifications
You must be signed in to change notification settings - Fork 14
/
utils.go
52 lines (39 loc) · 894 Bytes
/
utils.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
43
44
45
46
47
48
49
50
51
52
package getstream
import (
"errors"
"regexp"
"strings"
)
func ValidateFeedSlug(feedSlug string) (string, error) {
r, err := regexp.Compile(`^\w+$`)
if err != nil {
return "", err
}
feedSlug = strings.Replace(feedSlug, "-", "_", -1)
if !r.MatchString(feedSlug) {
return "", errors.New("invalid feedSlug")
}
return feedSlug, nil
}
func ValidateFeedID(feedID string) (string, error) {
r, err := regexp.Compile(`^\w+$`)
if err != nil {
return "", err
}
feedID = strings.Replace(feedID, "-", "_", -1)
if !r.MatchString(feedID) {
return "", errors.New("invalid feedID")
}
return feedID, nil
}
func ValidateUserID(userID string) (string, error) {
r, err := regexp.Compile(`^\w+$`)
if err != nil {
return "", err
}
userID = strings.Replace(userID, "-", "_", -1)
if !r.MatchString(userID) {
return "", errors.New("invalid userID")
}
return userID, nil
}