-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl.go
44 lines (41 loc) · 834 Bytes
/
url.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
package chrome
import (
"regexp"
"strings"
)
type (
URLHasPrefix string
URLHasSuffix string
URLContains string
URLEqual string
URLBase string
)
func compare(url string, value any) (res bool) {
if value == nil || value == "" {
res = true
} else {
switch v := value.(type) {
case string:
res = strings.HasPrefix(url, v)
case URLHasPrefix:
res = strings.HasPrefix(url, string(v))
case URLHasSuffix:
res = strings.HasSuffix(url, string(v))
case URLContains:
res = strings.Contains(url, string(v))
case URLEqual:
res = url == string(v)
case URLBase:
str := string(v)
if i := strings.Index(str, "?"); i > 0 {
str = str[:i]
}
res = strings.HasPrefix(url, str)
case *regexp.Regexp:
res = v.MatchString(url)
default:
panic("unsupported url type")
}
}
return
}