-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate.go
55 lines (47 loc) · 1.09 KB
/
validate.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
53
54
55
package rsmq
import (
"errors"
"regexp"
)
// Validation errors
var (
ErrInvalidQname = errors.New("queue name is in wrong pattern")
ErrInvalidVt = errors.New("visibility timeout is out of range [0, 9999999]")
ErrInvalidDelay = errors.New("delay is out of range [0, 9999999]")
ErrInvalidMaxsize = errors.New("max size is out of range [1024, 65536] and not -1")
ErrInvalidID = errors.New("id is in wrong pattern")
)
var (
regexpQname = regexp.MustCompile(`^([a-zA-Z\d_-]){1,160}$`)
regexpID = regexp.MustCompile(`^([a-zA-Z\d:]){32}$`)
)
func validateQname(val string) error {
if !regexpQname.MatchString(val) {
return ErrInvalidQname
}
return nil
}
func validateVt(val uint) error {
if val > 9999999 {
return ErrInvalidVt
}
return nil
}
func validateDelay(val uint) error {
if val > 9999999 {
return ErrInvalidDelay
}
return nil
}
func validateMaxsize(val int) error {
if val != -1 && (val < 1024 || val > 65536) {
return ErrInvalidMaxsize
}
return nil
}
func validateID(val string) error {
if !regexpID.MatchString(val) {
return ErrInvalidID
}
return nil
}