帮忙看看这代码吧

geekzone · · 2712 次点击 · 开始浏览    置顶
这是一个创建于 的主题,其中的信息可能已经有所发展或是发生改变。

代码在这里下载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 } 这个函数没看明白,用到哪里了?

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2712 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传