{"id":10006977,"date":"2022-12-15T18:33:13","date_gmt":"2022-12-15T10:33:13","guid":{"rendered":"https:\/\/ityet.com\/?p=10006977"},"modified":"2022-12-15T18:33:13","modified_gmt":"2022-12-15T10:33:13","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%ba%8c%e6%8e%a5%e5%8f%a3","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006977","title":{"rendered":"\u5e26\u8bfb |\u300aGo in Action\u300b(\u4e2d\u6587\uff1aGo\u8bed\u8a00\u5b9e\u6218)(\u4e8c)\u63a5\u53e3"},"content":{"rendered":"<h2>\u63a5\u53e3<\/h2>\n<h3>\u63a5\u53e3\u7684\u5b9a\u4e49<\/h3>\n<p>\u8fd9\u91cc\u7528\u4e00\u4e2a\u4f8b\u5b50\u8bf4\u660e\u4e86golang\u4e2d\u63a5\u53e3\u7684\u542b\u4e49\u4e0e\u7528\u6cd5\uff0c\u5148\u770b\u4ee3\u7801<\/p>\n<pre><code class=\"go\">        \/\/ 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)<\/code><\/pre>\n<p>\u4e0a\u9762\u8fd9\u6bb5\u4ee3\u7801\u662fsearch.go\u4e2d\u8c03\u7528Match\u51fd\u6570\u7684\u4ee3\u7801\uff0c\u5176\u4e2dMatch\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u201cmatcher\u201d\u5c31\u662f\u63a5\u53e3\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"go\">\/\/ Matcher defines the behavior required by types that want\n\/\/ to implement a new search type.\ntype Matcher interface {\n    Search(feed *Feed, searchTerm string) ([]*Result, error)\n}<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u4e2a\u63a5\u53e3\uff0c\u6211\u4eec\u7684\u5339\u914d\u5668\u5c31\u53ef\u4ee5\u7528\u4e00\u81f4\u4e14\u901a\u7528\u7684\u65b9\u6cd5\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u5339\u914d\u503c\uff0c\u662f\u4e0d\u662f\u5f88\u4f18\u96c5<img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043088671\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u63a5\u53e3\u7684\u547d\u540d<\/h3>\n<blockquote><p><em>\u547d\u540d\u63a5\u53e3\u7684\u65f6\u5019\uff0c\u4e5f\u9700\u8981\u9075\u5b88Golang\u7684\u547d\u540d\u60ef\u4f8b\u3002\u5982\u679c\u63a5\u53e3\u7c7b\u578b\u53ea\u5305\u542b<strong>\u4e00\u4e2a\u65b9\u6cd5<\/strong>\uff0c\u90a3\u4e48\u8fd9\u4e2a\u7c7b\u578b\u7684\u540d\u5b57\u4ee5<strong>er\u7ed3\u5c3e<\/strong>\u3002\u6211\u4eec\u7684\u4f8b\u5b50\u91cc\u5c31\u662f\u8fd9\u4e48\u505a\u7684\uff0c\u6240\u4ee5\u8fd9\u4e2a\u63a5\u53e3\u7684\u540d\u5b57\u53eb\u4f5cMatcher\u3002\u5982\u679c\u63a5\u53e3\u7c7b\u578b\u5185\u90e8\u58f0\u660e\u4e86\u591a\u4e2a\u65b9\u6cd5\uff0c\u5176\u540d\u5b57\u9700\u8981\u4e0e\u5176\u884c\u4e3a\u5173\u8054\u3002<\/em><\/p><\/blockquote>\n<h3>\u7c7b\u5b9e\u73b0\u63a5\u53e3<\/h3>\n<p>\u8fd9\u91cc\u63d0\u4f9b\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u8fd9\u4e2a\u63a5\u53e3\u7684\u7c7b\u7684\u5b9e\u73b0<\/p>\n<pre><code class=\"go\">package search\n\ntype defaultMatcher struct {\n}\n\nfunc (m defaultMatcher) Search(feed *Feed, searchTerm string) ([]*Result, error) {\n    return nil, nil\n}<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u6709\u4e24\u70b9\u9700\u8981\u8bf4\u660e\uff1a<br \/>1.\u8fd9\u4e2a\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a\u7c7b\uff08defaultMatcher\uff09\uff0c\u8fd9\u662f\u4e00\u4e2a\u7a7a\u7ed3\u6784\u4f53\uff0c\u7a7a\u7ed3\u6784\u4f53\u521b\u5efa\u7684\u65f6\u5019\u7cfb\u7edf\u4e0d\u4f1a\u5206\u914d\u4efb\u4f55\u5185\u5b58\uff0c\u4e0d\u9700\u8981\u7ef4\u62a4\u72b6\u6001\uff0c\u53ea\u9700\u8981\u5b9e\u73b0\u63a5\u53e3\u5373\u53ef\uff0c\u6545\uff0c\u7a7a\u7ed3\u6784\u4f53\u5f88\u9002\u5408\u521b\u5efa\u6ca1\u6709\u4efb\u4f55\u72b6\u6001\u7684\u7c7b\u578b\u3002<br \/>2.func \u540e\u9762 Search\u524d\u9762\u7684\u8fd9\u4e2a\u62ec\u53f7\u7684\u5185\u5bb9\u662f\u6307\u5b9a\u63a5\u6536\u8005\uff0c\u8bf4\u767d\u4e86\u5c31\u662f\u628a\u63a5\u4e0b\u6765\u8981\u5199\u7684\u51fd\u6570\u7ed1\u5b9a\u5728\u6307\u5b9a\u7684\u7c7b\u4e0a\uff0c\u7c7b\u4f3cJava\u7684\u6210\u5458\u65b9\u6cd5\u3002<\/p>\n<h3>\u63a5\u53e3\u65b9\u6cd5\u8c03\u7528\u53d7\u9650<\/h3>\n<p>\u56e0\u4e3a\u5927\u90e8\u5206\u65b9\u6cd5\u5728\u88ab\u8c03\u7528\u540e\u90fd\u9700\u8981\u7ef4\u62a4\u63a5\u6536\u8005\u7684\u503c\u7684\u72b6\u6001\uff0c\u6240\u4ee5\uff0c\u4e00\u4e2a<strong>\u6700\u4f73\u5b9e\u8df5<\/strong>\u662f\uff0c\u5c06\u65b9\u6cd5\u7684\u63a5\u6536\u8005\u58f0\u660e\u4e3a<strong>\u6307\u9488<\/strong>\u3002\u5bf9\u4e8edefaultMatcher\u7c7b\u578b\u6765\u8bf4\uff0c\u4f7f\u7528\u503c\u4f5c\u4e3a\u63a5\u6536\u8005\u662f\u56e0\u4e3a\u521b\u5efa\u4e00\u4e2adefaultMatcher\u7c7b\u578b\u7684\u503c\u4e0d\u9700\u8981\u5206\u914d\u5185\u5b58\u3002\u7531\u4e8edefaultMatcher\u4e0d\u9700\u8981\u7ef4\u62a4\u72b6\u6001\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u6307\u9488\u5f62\u5f0f\u7684\u63a5\u6536\u8005\u3002<br \/>\u4e0e\u76f4\u63a5\u901a\u8fc7\u503c\u6216\u8005\u6307\u9488\u8c03\u7528\u65b9\u6cd5\u4e0d\u540c\uff0c\u5982\u679c\u901a\u8fc7\u63a5\u53e3\u7c7b\u578b\u7684\u503c\u8c03\u7528\u65b9\u6cd5\uff0c\u89c4\u5219\u6709\u5f88\u5927\u4e0d\u540c\uff0c \u5982\u4ee3\u7801\u6e05\u53552-38\u6240\u793a\u3002\u4f7f\u7528<strong>\u6307\u9488<\/strong>\u4f5c\u4e3a\u63a5\u6536\u8005\u58f0\u660e\u7684\u65b9\u6cd5\uff0c\u53ea\u80fd\u5728\u63a5\u53e3\u7c7b\u578b\u7684\u503c\u662f\u4e00\u4e2a<strong>\u6307\u9488<\/strong>\u7684\u65f6\u5019\u88ab\u8c03\u7528\u3002\u4f7f\u7528<strong>\u503c<\/strong>\u4f5c\u4e3a\u63a5\u6536\u8005\u58f0\u660e\u7684\u65b9\u6cd5\uff0c\u5728\u63a5\u53e3\u7c7b\u578b\u7684\u503c\u4e3a<strong>\u503c<\/strong>\u6216\u8005<strong>\u6307\u9488<\/strong>\u65f6\uff0c\u90fd\u53ef\u4ee5\u88ab\u8c03\u7528\u3002<br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc4X1T\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<hr>\n<blockquote><p>\u53c2\u8003\uff1aKennedy W ,  Ketelsen B ,  Martin E S . Go in action.  2016.<\/p><\/blockquote>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc4VJk\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043091382\">https:\/\/segmentfault.com\/a\/1190000043091382<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a5\u53e3 \u63a5\u53e3\u7684\u5b9a\u4e49 \u8fd9\u91cc\u7528\u4e00\u4e2a\u4f8b\u5b50\u8bf4\u660e\u4e86golang\u4e2d\u63a5\u53e3\u7684\u542b\u4e49\u4e0e\u7528\u6cd5\uff0c\u5148\u770b\u4ee3\u7801 \/\/ Launch the g [&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-10006977","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\/10006977","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=10006977"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006977\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}