{"id":10006965,"date":"2022-12-15T05:43:08","date_gmt":"2022-12-14T21:43:08","guid":{"rendered":"https:\/\/ityet.com\/?p=10006965"},"modified":"2022-12-15T05:43:08","modified_gmt":"2022-12-14T21:43:08","slug":"%e5%b8%a6%e8%af%bb-%e3%80%8ago-in-action%e3%80%8b%e4%b8%ad%e6%96%87%ef%bc%9ago%e8%af%ad%e8%a8%80%e5%ae%9e%e6%88%98%e4%b8%80","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006965","title":{"rendered":"\u5e26\u8bfb |\u300aGo in Action\u300b(\u4e2d\u6587\uff1aGo\u8bed\u8a00\u5b9e\u6218)(\u4e00)"},"content":{"rendered":"<p>\u4e2a\u4eba\u89c9\u5f97\u300aGo in Action\u300b(\u4e2d\u6587\uff1aGo\u8bed\u8a00\u5b9e\u6218)\u76f8\u6bd4\u4e8e\u300aThe Go Programming Language\u300b(\u4e2d\u6587\uff1aGo\u8bed\u8a00\u5723\u7ecf)\u8981\u63a5\u5730\u6c14\u4e00\u4e9b\uff0c\u540e\u8005\u5f88\u50cf\u82cf\u4fc4\u7684\u6559\u6750\uff0c\u4e00\u677f\u4e00\u773c\uff0c\u81ea\u5e95\u5411\u4e0a \u3002\u524d\u8005\u66f4\u50cf\u7f8e\u5f0f\u6559\u6750\uff0c\u4e00\u4e0a\u6765\u5c31\u7ed9\u4f60\u4e00\u4e2a\u5b8c\u6574\u7684\u201c\u641c\u7d22\u6570\u636e\u201d\u7684\u9879\u76ee\uff0c\u7136\u540e\u81ea\u9876\u5411\u4e0b\uff0c\u6f5c\u79fb\u9ed8\u5316\u4e2d\u6559\u4f60\u60f3\u8981\u7684\u77e5\u8bc6\u3002\uff08\u6ca1\u6709\u5b70\u4f18\u5b70\u52a3\uff0c\u76f8\u6bd4\u4e8e\u5927\u9ed1\u4e66 \u4e2a\u4eba\u66f4\u504f\u7231 in action \u7cfb\u5217\uff0c\u8981\u60f3\u5b66\u624e\u5b9e\u5f53\u71362\u672c\u90fd\u8981\u770b\u5566\uff09<\/p>\n<hr>\n<h2>\u7b2c\u4e00\u7ae0Go\u8bed\u8a00\u7684\u4ecb\u7ecd<\/h2>\n<p>\u4ecb\u7ecd\u4e86Go\u7684\u4ea7\u751f\u7684\u539f\u56e0\uff0c\u53ca\u7279\u70b9\uff0c\u8fd9\u65b9\u9762\u7684\u6587\u7ae0\u5e16\u5b50\u592a\u591a\uff0c\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<h2>\u7b2c\u4e8c\u7ae0\u5982\u4f55\u5feb\u901f\u5f00\u59cb\u4e00\u4e2aGo\u7a0b\u5e8f<\/h2>\n<p>\u8fd9\u91cc\u7ed9\u51fa\u6211\u4eec\u8981\u5b66\u4e60\u7684\u7b2c\u4e00\u4e2a\u7a0b\u5e8f\u67b6\u6784\uff1a<br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc4VKM\" alt=\"\" title=\"\" loading=\"lazy\"><br \/>\u8fd9\u4e00\u7ae0\u4e3b\u8981\u901a\u8fc7\u5bf9\u7a0b\u5e8f\u7684\u9010\u884c\u8bb2\u89e3\uff0c\u5b9e\u73b0\u4e86\u5bf9json\u683c\u5f0f\u7684\u76ee\u6807\u6570\u636e\u8fdb\u884c\u641c\u7d22\u7684\u529f\u80fd\u3002<\/p>\n<p>\u4e0b\u9762\u5217\u51fa\u4e00\u4e9b\u4e2a\u4eba\u8ba4\u4e3a\u503c\u5f97\u5173\u6ce8\u7684\u70b9\uff1a<\/p>\n<h3>\u5173\u4e8e\u8bbf\u95ee\u6807\u8bc6\u7b26\uff1a<\/h3>\n<p>\u548cJava\u7684Public\/Private \u4e0d\u540c Go\u4f7f\u7528\u9996\u5b57\u6bcd\u5927\u5c0f\u5199\u6807\u8bc6\u662f\u5426\u80fd\u88ab\u5176\u4ed6\u5305\u4e2d\u7684\u4ee3\u7801\u76f4\u63a5\u8bbf\u95ee\u3002<\/p>\n<h3>\u5173\u4e8e\u521d\u59cb\u5316\uff1a<\/h3>\n<p>0\u503c\u7684\u521d\u59cb\u5316\u7528var\uff0c\u975e\u96f6\u503c\u7528:=<\/p>\n<h3>\u5173\u4e8e\u5f15\u7528\u4f20\u9012or\u503c\u4f20\u9012<\/h3>\n<p>golang\u6ca1\u6709\u5f15\u7528\u4f20\u9012\uff0c\u5168\u662f\u503c\u4f20\u9012\uff0c\u5c31\u7b97\u662f\u6307\u9488\u4e5f\u662f\u503c\u4f20\u9012\uff08\u5b58\u7684\u662f\u53d8\u91cf\u7684\u5185\u5b58\u5730\u5740\u7f62\u4e86\uff09<\/p>\n<h3>\u5173\u4e8e\u95ed\u5305\uff1a\u4ee5\u4e0b\u9762\u7684\u4ee3\u7801\u4e3a\u4f8b<\/h3>\n<pre><code class=\"go\">for _, feed := range feeds {\n        \/\/ Retrieve a matcher for the search.\n        matcher, exists := matchers[feed.Type]\n        if !exists {\n            matcher = matchers[&quot;default&quot;]\n        }\n\n        \/\/ Launch the goroutine to perform the search.\n        go func(matcher Matcher, feed *Feed) {\n            Match(matcher, feed, searchTerm, results)\n            waitGroup.Done()\n        }(matcher, feed)\n    }<\/code><\/pre>\n<p>\u6ce8\u610f\u5230\u95ed\u5305\u91cc\u9762\u5e76\u6ca1\u6709\u4f20\u5165&#8217;waitGroup&#8217;\uff0c\u4f46\u5374\u6210\u529f\u8bbf\u95ee\u5230\u4e86\uff0c\u5e76\u4e0d\u662f\u56e0\u4e3a\u8fd9\u4e2a\u533f\u540d\u51fd\u6570\u62ff\u5230\u4e86waitGroup\u7684\u526f\u672c\uff0c\u800c\u662f\u901a\u8fc7\u95ed\u5305\u76f4\u63a5\u8bbf\u95ee\u5230\u4e86\u5916\u5c42\u4f5c\u7528\u57df\u4e2dwaitGroup\u53d8\u91cf\u672c\u8eab\u3002<\/p>\n<h3>\u5173\u4e8e\u6570\u636e\u8f6c\u5316\uff1a<\/h3>\n<pre><code class=\"golang\">var feeds = [] * feed\nerr = json.NewDecoder(file).Decode(&amp;feeds)\nreturn feeds, err<\/code><\/pre>\n<p>\u8fd9\u79cd\u529f\u80fd\u4ee3\u7801\u7247\u6bb5\u5176\u5b9e\u53ef\u4ee5\u79ef\u7d2f\u4e00\u4e9b\uff0c\u5de5\u4f5c\u4e2d\u7528\u7684\u633a\u591a\u7684\uff0c\u5f53\u7136\u76f4\u63a5\u4f7f\u7528unmarshal\u4e5f\u53ef\uff0c\u56e0\u4e3a\u8fd9\u91ccDecode\u5c31\u662f\u7528unmarshal\u5c01\u88c5\u7684\u3002<\/p>\n<blockquote><p>\u53c2\u8003\uff1aKennedy W ,  Ketelsen B ,  Martin E S . Go in action.  2016.<br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc4VJk\" alt=\"\" title=\"\" loading=\"lazy\"><\/p><\/blockquote>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043082491\">https:\/\/segmentfault.com\/a\/1190000043082491<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e2a\u4eba\u89c9\u5f97\u300aGo in Action\u300b(\u4e2d\u6587\uff1aGo\u8bed\u8a00\u5b9e\u6218)\u76f8\u6bd4\u4e8e\u300aThe Go Programming Lan [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10006965","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006965"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006965\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}