-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutil.go
More file actions
47 lines (38 loc) · 781 Bytes
/
util.go
File metadata and controls
47 lines (38 loc) · 781 Bytes
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
package pipeline
import (
"net/url"
"strings"
"golang.org/x/net/html"
)
// TraverseTextNodes map nested node to find all text node
func TraverseTextNodes(node *html.Node, fn func(*html.Node)) {
if node == nil {
return
}
if node.Type == html.TextNode || node.Type == html.RawNode {
fn(node)
}
cur := node.FirstChild
for cur != nil {
next := cur.NextSibling
TraverseTextNodes(cur, fn)
cur = next
}
}
func isHost(hosts []string, src string) bool {
if src == "" {
return false
}
src = strings.ToLower(src)
srcURL, err := url.Parse(src)
if err != nil {
return false
}
for _, host := range hosts {
host = strings.Replace(host, "*.", "", 1)
if strings.HasSuffix(srcURL.Hostname(), strings.ToLower(host)) {
return true
}
}
return false
}