-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathlink_validator.go
More file actions
32 lines (25 loc) · 727 Bytes
/
link_validator.go
File metadata and controls
32 lines (25 loc) · 727 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
package main
import (
"net/url"
"github.com/temoto/robotstxt"
)
type linkValidator struct {
hostname string
sitemapURLs map[string]struct{}
robotsData *robotstxt.RobotsData
}
func newLinkValidator(hostname string, robotsData *robotstxt.RobotsData, sitemap map[string]struct{}) *linkValidator {
return &linkValidator{hostname, sitemap, robotsData}
}
// Validate validates a link and returns true if it is valid as one of an HTML page.
func (v *linkValidator) Validate(u *url.URL) bool {
if v.sitemapURLs != nil {
if _, ok := v.sitemapURLs[u.String()]; !ok {
return false
}
}
if v.robotsData != nil && !v.robotsData.TestAgent(u.Path, agentName) {
return false
}
return u.Hostname() == v.hostname
}