代码在这里下载http://yunpan.cn/QNwGTz2VArLCq
这里也可以下载https://gist.github.com/rowland/984989
Go http client with cookie support 代码的功能
type HttpClient struct {
client http.Client
jar CookieJar
Log io.Writer
patterns map[*regexp.Regexp]func(matches []string)
}
上面的这个patterns有什么作用?
func (this *HttpClient) invokeCallbacks(url string) {
for re, cb := range this.patterns {
fmt.Printf("Examining %s...\n", re)
matches := re.FindStringSubmatch(url)
if matches != nil {
fmt.Printf("Executing callback for %s...\n", re)
cb(matches)
}
}
}
这个函数是怎么执行的?
func (this *HttpClient) Match(pattern string, callback func(matches []string)) {
if this.patterns == nil {
this.patterns = make(map[*regexp.Regexp]func(matches []string))
}
re := regexp.MustCompile(ExpandRegex(pattern))
this.patterns[re] = callback
}
这个函数没看明白,用到哪里了?
有疑问加站长微信联系(非本文作者)