{"id":207564,"date":"2025-07-08T14:10:06","date_gmt":"2025-07-08T06:10:06","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207564\/"},"modified":"2025-07-08T14:10:06","modified_gmt":"2025-07-08T06:10:06","slug":"golang-%e8%b0%83%e7%94%a8%e5%85%b7%e6%9c%89%e4%b8%8d%e5%90%8c%e5%8f%82%e6%95%b0%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207564\/","title":{"rendered":"Golang \u8c03\u7528\u5177\u6709\u4e0d\u540c\u53c2\u6570\u7684\u65b9\u6cd5"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>Golang \u8c03\u7528\u5177\u6709\u4e0d\u540c\u53c2\u6570\u7684\u65b9\u6cd5<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-23 17:15:34<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGolang \u8c03\u7528\u5177\u6709\u4e0d\u540c\u53c2\u6570\u7684\u65b9\u6cd5\u300b<\/span>\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6709\u4e00\u4e2a\u7528\u4f8b\uff0c\u6211\u9700\u8981\u6267\u884c\u4e00\u7cfb\u5217\u5177\u6709\u4e0d\u540c\u53c2\u6570\u7684\u65b9\u6cd5\uff0c\u5982\u679c\u9047\u5230\u7279\u5b9a\u7684\u8fd4\u56de\u503c\uff0c\u90a3\u4e48\u6211\u9700\u8981\u505c\u6b62\u6267\u884c\u3002\u7c7b\u4f3c\u7684\u65b9\u6cd5\u5927\u7ea6\u6709 50 \u79cd\u5de6\u53f3\u3002<\/p>\n<p>\u8fd9\u91cc\u7ed9\u4f60\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u8fd9\u662f\u6211\u7684\u7528\u4f8b\u3002<\/p>\n<pre>func method1(param1 type1, param2 type2, param3 type3) bool {\n    \/\/ here i use only param1 and other 2 params are not being used. \n    if some condition on param1 {\n        return true\n    }\n    return false\n}\n<\/pre>\n<pre>func method2(param1 type1, param2 type2, param3 type3) bool {\n    \/\/ here i use param2 and param3. param1 is not used \n    if some condition on param2 and param3 {\n        return true\n    }\n    return false\n}<\/pre>\n<p>\u8c03\u7528\u8005\u65b9\u6cd5\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre>    rejectionFuncs := []func(type1,type2,type3) bool {\n        Method1, Method2,\n    }\n\n    for _, s := range rejectionFuncs {\n        rejected := s(param1, param2, param3)\n        if rejected {\n            return false\n        }\n    }\n<\/pre>\n<p>\u6211\u53ea\u80fd\u60f3\u5230\u8fd9\u79cd\u65b9\u5f0f\u4ee5\u4f18\u96c5\u7684\u65b9\u5f0f\u6267\u884c\u4e00\u7cfb\u5217\u65b9\u6cd5\uff0c\u4f46\u8fd9\u6837\u505a\u7684\u7f3a\u70b9\u662f\u6211\u53ef\u4ee5\u770b\u5230\u6709\u5f88\u591a\u65b9\u6cd5\u6ca1\u6709\u4f7f\u7528\u53c2\u6570\u3002\u5982\u679c\u5728\u4ee3\u7801\u8d44\u683c\u68c0\u67e5\u4e0a\u8fd0\u884c\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u4f1a\u62b1\u6028\u6211\u6ca1\u6709\u4f7f\u7528\u53c2\u6570\u3002<\/p>\n<p>\u6709\u4ec0\u4e48\u529e\u6cd5\u53ef\u4ee5\u7b80\u5316\u8fd9\u91cc\u7684\u4ee3\u7801\u5417\uff1f <\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u4e0d\u4f7f\u7528\u53c2\u6570\u5e76\u4e0d\u662f\u4e00\u4e2a\u9519\u8bef\uff0c\u4e8b\u5b9e\u4e0a\uff0c\u5f53\u60a8\u60f3\u8981\u5b9e\u73b0\u4e00\u4e2a\u5177\u6709\u5e26\u53c2\u6570\u7684\u65b9\u6cd5\u7684\u63a5\u53e3\u65f6\uff0c\u901a\u5e38\u4f1a\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\uff0c\u4f46\u60a8\u7684\u5177\u4f53\u5b9e\u73b0\u4e0d\uff08\u9700\u8981\uff09\u4f7f\u7528\u5b83\u4eec\u3002<\/p>\n<p>\u5728\u60a8\u7684\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u7b80\u5316\u7684\u4e00\u4ef6\u4e8b\u662f\u5c06\u53c2\u6570\u5305\u88c5\u5728\u7ed3\u6784\u4e2d\uff0c\u5e76\u4e14\u53ea\u9700\u5c06\u7ed3\u6784\uff08\u6216\u6307\u5411\u7ed3\u6784\u7684\u6307\u9488\uff09\u4f20\u9012\u7ed9\u51fd\u6570\u3002\u8fd9\u4e5f\u5c06\u4f7f\u60a8\u7684\u4ee3\u7801\u8d28\u91cf\u68c0\u67e5\u4eba\u5458\u4fdd\u6301\u51b7\u9759\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207564","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207564"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207564\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}