https://github.com/goinaction/code

[root@hadoop3 sample]# go run main.go
2018/07/30 17:45:39 Register default matcher
2018/07/30 17:45:39 Register rss matcher
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=1001]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=46]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=7]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=10]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=39]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=43]
2018/07/30 17:45:39 Search Feed Type[rss] Site[bbci] For URI[http://feeds.bbci.co.uk/news/rss.xml]
2018/07/30 17:45:39 Search Feed Type[rss] Site[bbci] For URI[http://feeds.bbci.co.uk/news/business/rss.xml]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=1008]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=1006]
2018/07/30 17:45:39 Search Feed Type[rss] Site[cnn] For URI[http://rss.cnn.com/rss/cnn_topstories.rss]
2018/07/30 17:45:39 Search Feed Type[rss] Site[bbci] For URI[http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=1007]
2018/07/30 17:45:39 Search Feed Type[rss] Site[cnn] For URI[http://rss.cnn.com/rss/cnn_world.rss]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=1057]
2018/07/30 17:45:39 Search Feed Type[rss] Site[cnn] For URI[http://rss.cnn.com/rss/cnn_us.rss]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=1021]
2018/07/30 17:45:39 Search Feed Type[rss] Site[cnn] For URI[http://rss.cnn.com/rss/cnn_allpolitics.rss]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=1012]
2018/07/30 17:45:39 Search Feed Type[rss] Site[cnn] For URI[http://rss.cnn.com/rss/cnn_crime.rss]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=1003]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=2]
2018/07/30 17:45:39 Search Feed Type[rss] Site[cnn] For URI[http://rss.cnn.com/rss/cnn_tech.rss]
2018/07/30 17:45:39 Search Feed Type[rss] Site[cnn] For URI[http://rss.cnn.com/rss/cnn_health.rss]
2018/07/30 17:45:39 Search Feed Type[rss] Site[cnn] For URI[http://rss.cnn.com/rss/cnn_topstories.rss]
2018/07/30 17:45:39 Search Feed Type[rss] Site[foxnews] For URI[http://feeds.foxnews.com/foxnews/opinion?format=xml]
2018/07/30 17:45:39 Search Feed Type[rss] Site[foxnews] For URI[http://feeds.foxnews.com/foxnews/politics?format=xml]
2018/07/30 17:45:39 Search Feed Type[rss] Site[foxnews] For URI[http://feeds.foxnews.com/foxnews/national?format=xml]
2018/07/30 17:45:39 Search Feed Type[rss] Site[foxnews] For URI[http://feeds.foxnews.com/foxnews/world?format=xml]
2018/07/30 17:45:39 Search Feed Type[rss] Site[nbcnews] For URI[http://feeds.nbcnews.com/feeds/topstories]
2018/07/30 17:45:39 Search Feed Type[rss] Site[nbcnews] For URI[http://feeds.nbcnews.com/feeds/usnews]
2018/07/30 17:45:39 Search Feed Type[rss] Site[nbcnews] For URI[http://rss.msnbc.msn.com/id/21491043/device/rss/rss.xml]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=3]
2018/07/30 17:45:39 Search Feed Type[rss] Site[nbcnews] For URI[http://rss.msnbc.msn.com/id/21491571/device/rss/rss.xml]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=5]
2018/07/30 17:45:39 Search Feed Type[rss] Site[nbcnews] For URI[http://rss.msnbc.msn.com/id/28180066/device/rss/rss.xml]
2018/07/30 17:45:39 Search Feed Type[rss] Site[npr] For URI[http://www.npr.org/rss/rss.php?id=13]
2018/07/30 17:45:39 Get http://rss.cnn.com/rss/cnn_allpolitics.rss: read tcp 192.168.3.103:54478->216.58.200.51:80: read: connection reset by peer
2018/07/30 17:45:39 Get http://rss.cnn.com/rss/cnn_topstories.rss: read tcp 192.168.3.103:54484->216.58.200.51:80: read: connection reset by peer
2018/07/30 17:45:39 Get http://rss.cnn.com/rss/cnn_health.rss: read tcp 192.168.3.103:54482->216.58.200.51:80: read: connection reset by peer
2018/07/30 17:45:39 Get http://rss.cnn.com/rss/cnn_crime.rss: read tcp 192.168.3.103:54476->216.58.200.51:80: read: connection reset by peer
2018/07/30 17:45:39 Get http://rss.cnn.com/rss/cnn_us.rss: read tcp 192.168.3.103:54488->216.58.200.51:80: read: connection reset by peer
2018/07/30 17:45:39 Get http://rss.cnn.com/rss/cnn_world.rss: read tcp 192.168.3.103:54486->216.58.200.51:80: read: connection reset by peer
2018/07/30 17:45:39 Description:
If Ronald Reagan was the “Teflon president,” Donald Trump must be the Incredible Hulk president. The more the left and the media attack him, the stronger he gets.<img src="http://feeds.feedburner.com/~r/foxnews/opinion/~4/bVrx9JLgLWI" height="1" width="1" alt=""/> 2018/07/30 17:45:39 Description:
We look at the latest strong economic numbers and the effect tariffs may have on the president's base. 2018/07/30 17:45:39 Description:
Freeman Hrabowski, president of the University of Maryland, Baltimore County, talks about the importance of mentoring in academia, especially in science, technology, engineering and math fields. 2018/07/30 17:45:39 Description:
A dispute between the president and<em> The New York Times</em> publisher revives questions about the impact of Trump's anti-press rhetoric. He decried a supposed media conspiracy against his administration. 2018/07/30 17:45:40 Description:
Retail and fast-food workers protesting for higher pay are creating a new kind of U.S. labor movement. <em>Chicago Tribune</em> columnist Clarence Page argues that the president could "set a good example" by requiring fast-food vendors who have contracts with the federal government to pay minimum wage. 2018/07/30 17:45:40 Description:
A dispute between the president and<em> The New York Times</em> publisher revives questions about the impact of Trump's anti-press rhetoric. He decried a supposed media conspiracy against his administration. 2018/07/30 17:45:40 Description:
A dispute between the president and<em> The New York Times</em> publisher revives questions about the impact of Trump's anti-press rhetoric. He decried a supposed media conspiracy against his administration. 2018/07/30 17:45:40 Description:
The moment when the president articulated his attitude with pithy perfection came when he told the Veterans of Foreign Wars that "what you're seeing and what you're reading is not what's happening." 2018/07/30 17:45:40 Description:
The U.S. president publicly humiliated our most important allies and then said everything was great. We need positive, unifying leadership, writes a former U.S. Army Europe commander. 2018/07/30 17:45:40 Description:
A dispute between the president and<em> The New York Times</em> publisher revives questions about the impact of Trump's anti-press rhetoric. He decried a supposed media conspiracy against his administration. 2018/07/30 17:45:40 Description:
Last year a song about freedom became a rallying cry as Zimbabwe unseated longtime president Robert Mugabe. Now the anthem has become tainted by the lack of tangible change for people there. 2018/07/30 17:45:40 Description:
Last year a song about freedom became a rallying cry as Zimbabwe unseated longtime president Robert Mugabe. Now the anthem has become tainted by the lack of tangible change for people there. 2018/07/30 17:45:40 Description:
We look at the latest strong economic numbers and the effect tariffs may have on the president's base. 2018/07/30 17:45:40 Description:
The president goes back and forth about what he accepts and denies about Russian election interference. Even so, his recent warning about an attack that helps Democrats is a cogent one. 2018/07/30 17:45:40 Description:
The president demanded cooperation from the Democrats over immigration, threatening to close the government in order to achieve his goals. 2018/07/30 17:45:40 Get http://rss.cnn.com/rss/cnn_tech.rss: read tcp 192.168.3.103:54480->216.58.200.51:80: read: connection reset by peer
2018/07/30 17:45:40 Get http://rss.cnn.com/rss/cnn_topstories.rss: read tcp 192.168.3.103:54474->216.58.200.51:80: read: connection reset by peer
2018/07/30 17:45:41 expected element type <rss> but have <html>
2018/07/30 17:45:41 expected element type <rss> but have <html>
2018/07/30 17:45:41 expected element type <rss> but have <html>
2018/07/30 17:46:09 Get http://feeds.bbci.co.uk/news/rss.xml: dial tcp 66.220.155.12:80: i/o timeout
2018/07/30 17:46:09 Get http://feeds.bbci.co.uk/news/business/rss.xml: dial tcp 66.220.155.12:80: i/o timeout
2018/07/30 17:46:09 Get http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml: dial tcp 66.220.155.12:80: i/o timeout
[root@hadoop3 sample]# tree
.
├── data
│   └── data.json
├── main.go
├── matchers
│   └── rss.go
└── search
├── default.go
├── feed.go
├── match.go
└── search.go 3 directories, 7 files
[root@hadoop3 sample]# tree /home/ctGO/goInAction/
/home/ctGO/goInAction/
└── code
├── chapter1
│   └── channels
│   └── hellochannels.go
├── chapter10
│   ├── listing01
│   │   └── listing01.go
│   ├── listing02
│   │   └── listing02.go
│   ├── listing03
│   │   └── listing03.go
│   ├── listing04
│   │   └── listing04.go
│   ├── listing05
│   │   └── listing05.go
│   └── listing06
│   ├── listing06
│   ├── listing06.go
│   └── pubsub
│   └── pubsub.go
├── chapter2
│   └── sample
│   ├── data
│   │   └── data.json
│   ├── main.go
│   ├── matchers
│   │   └── rss.go
│   └── search
│   ├── default.go
│   ├── feed.go
│   ├── match.go
│   └── search.go
├── chapter3
│   ├── dbdriver
│   │   ├── main.go
│   │   └── postgres
│   │   └── postgres.go
│   ├── wordcount
│   │   ├── gowords.txt
│   │   └── wordcount.go
│   └── words
│   └── count.go
├── chapter5
│   ├── listing11
│   │   └── listing11.go
│   ├── listing34
│   │   └── listing34.go
│   ├── listing35
│   │   └── listing35.go
│   ├── listing36
│   │   └── listing36.go
│   ├── listing46
│   │   └── listing46.go
│   ├── listing48
│   │   └── listing48.go
│   ├── listing50
│   │   └── listing50.go
│   ├── listing56
│   │   └── listing56.go
│   ├── listing60
│   │   └── listing60.go
│   ├── listing64
│   │   ├── counters
│   │   │   └── counters.go
│   │   └── listing64.go
│   ├── listing68
│   │   ├── counters
│   │   │   └── counters.go
│   │   └── listing68.go
│   ├── listing71
│   │   ├── entities
│   │   │   └── entities.go
│   │   └── listing71.go
│   └── listing74
│   ├── entities
│   │   └── entities.go
│   └── listing74.go
├── chapter6
│   ├── listing01
│   │   └── listing01.go
│   ├── listing04
│   │   └── listing04.go
│   ├── listing07
│   │   └── listing07.go
│   ├── listing09
│   │   └── listing09.go
│   ├── listing13
│   │   └── listing13.go
│   ├── listing15
│   │   └── listing15.go
│   ├── listing16
│   │   └── listing16.go
│   ├── listing20
│   │   └── listing20.go
│   ├── listing22
│   │   └── listing22.go
│   └── listing24
│   └── listing24.go
├── chapter7
│   └── patterns
│   ├── pool
│   │   ├── main
│   │   │   └── main.go
│   │   └── pool.go
│   ├── runner
│   │   ├── main
│   │   │   └── main.go
│   │   └── runner.go
│   ├── search
│   │   ├── main
│   │   │   └── main.go
│   │   ├── searchers.go
│   │   └── search.go
│   ├── semaphore
│   │   └── semaphore.go
│   └── work
│   ├── main
│   │   └── main.go
│   └── work.go
├── chapter8
│   ├── listing03
│   │   └── listing03.go
│   ├── listing11
│   │   └── listing11.go
│   ├── listing24
│   │   └── listing24.go
│   ├── listing27
│   │   └── listing27.go
│   ├── listing29
│   │   └── listing29.go
│   ├── listing31
│   │   └── listing31.go
│   ├── listing37
│   │   └── listing37.go
│   └── listing46
│   └── listing46.go
├── chapter9
│   ├── listing01
│   │   └── listing01_test.go
│   ├── listing08
│   │   └── listing08_test.go
│   ├── listing12
│   │   └── listing12_test.go
│   ├── listing17
│   │   ├── handlers
│   │   │   ├── handlers_example_test.go
│   │   │   ├── handlers.go
│   │   │   └── handlers_test.go
│   │   └── listing17.go
│   └── listing28
│   └── listing28_test.go
└── README.md 77 directories, 75 files
[root@hadoop3 sample]#

  

https://github.com/goinaction/code/blob/master/chapter2/sample/search/search.go

	// Launch a goroutine to monitor when all the work is done.
go func() {
// Wait for everything to be processed.
waitGroup.Wait() // Close the channel to signal to the Display
// function that we can exit the program.
close(results)
}()

  

// Run performs the search logic.
func Run(searchTerm string) {
// Retrieve the list of feeds to search through.
feeds, err := RetrieveFeeds()
if err != nil {
log.Fatal(err)
} // Create an unbuffered channel to receive match results to display.
results := make(chan *Result) // Setup a wait group so we can process all the feeds.
var waitGroup sync.WaitGroup // Set the number of goroutines we need to wait for while
// they process the individual feeds.
waitGroup.Add(len(feeds)) // Launch a goroutine for each feed to find the results.
for _, feed := range feeds {
// Retrieve a matcher for the search.
matcher, exists := matchers[feed.Type]
if !exists {
matcher = matchers["default"]
} // Launch the goroutine to perform the search.
go func(matcher Matcher, feed *Feed) {
Match(matcher, feed, searchTerm, results)
waitGroup.Done()
}(matcher, feed)
} // Launch a goroutine to monitor when all the work is done.
go func() {
// Wait for everything to be processed.
waitGroup.Wait() // Close the channel to signal to the Display
// function that we can exit the program.
close(results)
}() // Start displaying results as they are available and
// return after the final result is displayed.
Display(results)
}

go通道消息共享

最新文章

  1. ORACLE 11gR2 DG(Physical Standby)日常维护02
  2. linux作业
  3. 性能测试工具 转自https://yq.aliyun.com/articles/35149?spm=5176.100239.blogcont35147.8.rsow6k
  4. 使用PHPExcel导入Excel到MySql
  5. c++ ado 调用存储过程并得到输出参数和返回值
  6. mousewheel 模拟滚动
  7. mysql 查看是否存在某一张表
  8. Java中的BufferedReader 的readLine方法
  9. JDicom使用指南
  10. having count(*) &gt; 1
  11. SEO为什么要求网页设计师用DIV+CSS布局网页?
  12. poj 2689 Prime Distance(大区间素数)
  13. Jenkins环境搭建(4)-配置定时构建
  14. python基础14_文件操作
  15. Behavior Question - Most challenging project.
  16. mysql自定义函数与过程中写法的注意事项
  17. EF数据库优先模式(二)
  18. python——type()、metaclass元类和精简ORM框架
  19. lua内存管理
  20. ios的一些经验记录1

热门文章

  1. nginx的详解(三)
  2. 新浪微博error:redirect_uri_mismatch的解决方法 [
  3. HDU 5073 Galaxy ——乱搞
  4. Codeforces956D. Contact ATC
  5. PHP验证码显示不出来
  6. 转载免费的SSL证书
  7. (3)Swing常用组件
  8. Codeforces 487B Strip (ST表+线段树维护DP 或 单调队列优化DP)
  9. MySql的架构和历史
  10. NOIPSB评测机+SB题DAY2