{"id":19038,"date":"2023-02-28T21:50:01","date_gmt":"2023-02-28T13:50:01","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=19038"},"modified":"2023-07-30T23:02:01","modified_gmt":"2023-07-30T15:02:01","slug":"go%e8%af%ad%e8%a8%80interface%e6%95%88%e7%8e%87%e4%bd%8e%ef%bc%8c%e6%9c%89%e6%b2%a1%e6%9c%89%e4%bb%80%e4%b9%88%e6%9b%bf%e4%bb%a3%e5%93%81","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/19038.html","title":{"rendered":"Go\u8bed\u8a00interface\u6548\u7387\u4f4e\uff0c\u6709\u6ca1\u6709\u4ec0\u4e48\u66ff\u4ee3\u54c1"},"content":{"rendered":"<blockquote class=\"wp-block-quote\">\n<p>Go\u8bed\u8a00interface\u6548\u7387\u4f4e\uff0cGo\u4e0d\u662f\u4e3a\u8fd9\u79cd\u7a0b\u5ea6\u7684\u4f18\u5316\u8bbe\u8ba1\u7684\uff0c\u5982\u679c\u975e\u8981\u8fdb\u884c\u8fd9\u4e48micro\u7684\u4f18\u5316\uff0c\u5efa\u8bae\u4f7f\u7528C++\/Rust\u7b49\u8bed\u8a00\uff0c\u6216\u8005\u7528un<a href=\"https:\/\/docs.pingcode.com\/agile\/agile-at-scale\/what-is-safe\" target=\"_blank\">SAFe<\/a>\u5305\u3002\u4e00\u822c\u6765\u8bb2\uff0c\u5927\u5bb6\u90fd\u662f\u7528\u7a7a\u95f4\u6362\u65f6\u95f4\uff0c\u4e00\u4e2a\u7ed3\u6784\u4f53\u6709\u591a\u79cd\u53d8\u91cf\u7c7b\u578b\uff0c\u8fd9\u6837\u4f7f\u5f97\u7ed3\u6784\u4f53\u53ef\u4ee5\u8868\u793a\u52a8\u6001\u7c7b\u578b\u6570\u636e\u3002<\/p>\n<\/blockquote>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" alt=\"\" class=\"wp-image-19039\" decoding=\"async\" height=\"421\" sizes=\"(max-width: 680px) 100vw, 680px\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/02\/\u6dfb\u52a0\u6807\u9898-19-13.png?x-oss-process=image\/auto-orient,1\/format,webp\" srcset=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/02\/\u6dfb\u52a0\u6807\u9898-19-13.png?x-oss-process=image\/auto-orient,1\/format,webp 680w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/02\/\u6dfb\u52a0\u6807\u9898-19-13-300x186.png 300w\" width=\"680\"\/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001Go\u8bed\u8a00interface\u6548\u7387\u4f4e\uff0c\u6709\u6ca1\u6709\u4ec0\u4e48\u66ff\u4ee3\u54c1<\/strong><\/h2>\n<p>Go\u8bed\u8a00interface\u6548\u7387\u4f4e\uff0cGo\u4e0d\u662f\u4e3a\u8fd9\u79cd\u7a0b\u5ea6\u7684\u4f18\u5316\u8bbe\u8ba1\u7684\uff0c\u5982\u679c\u975e\u8981\u8fdb\u884c\u8fd9\u4e48micro\u7684\u4f18\u5316\uff0c\u5efa\u8bae\u4f7f\u7528C++\/Rust\u7b49\u8bed\u8a00\uff0c\u6216\u8005\u7528unsafe\u5305\u3002\u4e00\u822c\u6765\u8bb2\uff0c\u5927\u5bb6\u90fd\u662f\u7528\u7a7a\u95f4\u6362\u65f6\u95f4\uff0c\u4e00\u4e2a\u7ed3\u6784\u4f53\u6709\u591a\u79cd\u53d8\u91cf\u7c7b\u578b\uff0c\u8fd9\u6837\u4f7f\u5f97\u7ed3\u6784\u4f53\u53ef\u4ee5\u8868\u793a\u52a8\u6001\u7c7b\u578b\u6570\u636e\u3002\u5982\u679c\u8fd8\u9700\u8981\u8282\u7701\u7a7a\u95f4\u7684\u8bdd\uff0c\u4f18\u5316\u7ed3\u6784\u4f53\u5185\u5b58\u5e03\u5c40\uff0c\u914d\u5408un<a href=\"https:\/\/docs.pingcode.com\/agile\/agile-at-scale\/what-is-safe\" target=\"_blank\">SAFe<\/a>\u5305\u786c\u6838\u8f6c\u6362\u5e94\u8be5\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>\u5982\u679c\u8bf4goroutine\u548cchannel\u662fGo\u5e76\u53d1\u7684\u4e24\u5927\u57fa\u77f3\uff0c\u90a3\u4e48\u63a5\u53e3\u662fGo\u8bed\u8a00\u7f16\u7a0b\u4e2d\u6570\u636e\u7c7b\u578b\u7684\u5173\u952e\u3002\u5728Go\u8bed\u8a00\u7684\u5b9e\u9645\u7f16\u7a0b\u4e2d\uff0c\u51e0\u4e4e\u6240\u6709\u7684\u6570\u636e\u7ed3\u6784\u90fd\u56f4\u7ed5\u63a5\u53e3\u5c55\u5f00\uff0c\u63a5\u53e3\u662fGo\u8bed\u8a00\u4e2d\u6240\u6709\u6570\u636e\u7ed3\u6784\u7684\u6838\u5fc3\u3002<\/p>\n<p>Go\u4e0d\u662f\u4e00\u79cd\u5178\u578b\u7684OO\u8bed\u8a00\uff0c\u5b83\u5728\u8bed\u6cd5\u4e0a\u4e0d\u652f\u6301\u7c7b\u548c\u7ee7\u627f\u7684\u6982\u5ff5\u3002<\/p>\n<p>\u6ca1\u6709\u7ee7\u627f\u662f\u5426\u5c31\u65e0\u6cd5\u62e5\u6709\u591a\u6001\u884c\u4e3a\u4e86\u5462\uff1f\u7b54\u6848\u662f\u5426\u5b9a\u7684\uff0cGo\u8bed\u8a00\u5f15\u5165\u4e86\u4e00\u79cd\u65b0\u7c7b\u578b\u2014Interface\uff0c\u5b83\u5728\u6548\u679c\u4e0a\u5b9e\u73b0\u4e86\u7c7b\u4f3c\u4e8eC++\u7684\u201c\u591a\u6001\u201d\u6982\u5ff5\uff0c\u867d\u7136\u4e0eC++\u7684\u591a\u6001\u5728\u8bed\u6cd5\u4e0a\u5e76\u975e\u5b8c\u5168\u5bf9\u7b49\uff0c\u4f46\u81f3\u5c11\u5728\u6700\u7ec8\u5b9e\u73b0\u7684\u6548\u679c\u4e0a\uff0c\u5b83\u6709\u591a\u6001\u7684\u5f71\u5b50\u3002<\/p>\n<p>\u867d\u7136Go\u8bed\u8a00\u6ca1\u6709\u7c7b\u7684\u6982\u5ff5\uff0c\u4f46\u5b83\u652f\u6301\u7684\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u5b9a\u4e49\u5bf9\u5e94\u7684method(s)\u3002\u672c\u8d28\u4e0a\u8bf4\uff0c\u6240\u8c13\u7684method(s)\u5176\u5b9e\u5c31\u662f\u51fd\u6570\uff0c\u53ea\u4e0d\u8fc7\u4e0e\u666e\u901a\u51fd\u6570\u76f8\u6bd4\uff0c\u8fd9\u7c7b\u51fd\u6570\u662f\u4f5c\u7528\u5728\u67d0\u4e2a\u6570\u636e\u7c7b\u578b\u4e0a\u7684\uff0c\u6240\u4ee5\u5728\u51fd\u6570\u7b7e\u540d\u4e2d\uff0c\u4f1a\u6709\u4e2areceiver(\u63a5\u6536\u5668)\u6765\u8868\u660e\u5f53\u524d\u5b9a\u4e49\u7684\u51fd\u6570\u4f1a\u4f5c\u7528\u5728\u8be5receiver\u4e0a\u3002<\/p>\n<p>Go\u8bed\u8a00\u652f\u6301\u7684\u9664Interface\u7c7b\u578b\u5916\u7684\u4efb\u4f55\u5176\u5b83\u6570\u636e\u7c7b\u578b\u90fd\u53ef\u4ee5\u5b9a\u4e49\u5176method\uff08\u800c\u5e76\u975e\u53ea\u6709struct\u624d\u652f\u6301method\uff09\uff0c\u53ea\u4e0d\u8fc7\u5b9e\u9645\u9879\u76ee\u4e2d\uff0cmethod(s)\u591a\u5b9a\u4e49\u5728struct\u4e0a\u800c\u5df2\u3002<br \/>\u4ece\u8fd9\u4e00\u70b9\u6765\u770b\uff0c\u6211\u4eec\u53ef\u4ee5\u628aGo\u4e2d\u7684struct\u770b\u4f5c\u662f\u4e0d\u652f\u6301\u7ee7\u627f\u884c\u4e3a\u7684\u8f7b\u91cf\u7ea7\u7684\u201c\u7c7b\u201d\u3002<\/p>\n<p>\u4ece\u8bed\u6cd5\u4e0a\u770b\uff0cInterface\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6216\u4e00\u7ec4method(s)\uff0c\u8fd9\u4e9bmethod(s)\u53ea\u6709\u51fd\u6570\u7b7e\u540d\uff0c\u6ca1\u6709\u5177\u4f53\u7684\u5b9e\u73b0\u4ee3\u7801\uff08\u6709\u6ca1\u6709\u8054\u60f3\u8d77C++\u4e2d\u7684\u865a\u51fd\u6570\uff1f\uff09\u3002\u82e5\u67d0\u4e2a\u6570\u636e\u7c7b\u578b\u5b9e\u73b0\u4e86Interface\u4e2d\u5b9a\u4e49\u7684\u90a3\u4e9b\u88ab\u79f0\u4e3a\u201dmethods\u201d\u7684\u51fd\u6570\uff0c\u5219\u79f0\u8fd9\u4e9b\u6570\u636e\u7c7b\u578b\u5b9e\u73b0\uff08implement\uff09\u4e86interface\u3002<\/p>\n<p><strong>\u5ef6\u4f38\u9605\u8bfb\uff1a<\/strong><\/p>\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001Go Reviverevive<\/strong><\/h2>\n<p>\u662f\u4e00\u4e2a Go \u8bed\u8a00\u7684\u4ee3\u7801\u8d28\u91cf\u68c0\u6d4b\u5de5\u5177(Linter for Go)\uff0c\u5177\u6709\u5feb\u901f\u3001\u53ef\u914d\u7f6e\u3001\u53ef\u6269\u5c55\u3001\u7075\u6d3b\u548c\u7f8e\u89c2\u7b49\u7279\u6027\uff0c\u53ef\u4f5c\u4e3a golint \u7684\u66ff\u4ee3\u65b9\u6848\u3002\u867d\u7136 golint \u5f88\u53d7\u6b22\u8fce\uff0c\u4f46\u662f revive \u63d0\u4f9b\u4e86\u66f4\u591a\u65b0\u529f\u80fd\uff0c\u503c\u5f97\u4f60\u53bb\u82b1\u65f6\u95f4\u7814\u7a76\uff0c\u4f8b\u5982\uff0c\u5b83\u8fd0\u884c\u5f97\u66f4\u5feb(\u8f83\u9ad8\u53ef\u8fbe6x!)\uff0c\u5141\u8bb8\u4f7f\u7528 TOML \u6587\u4ef6\u914d\u7f6e linting \u89c4\u5219\uff0c\u5e76\u63d0\u4f9b\u66f4\u591a\u89c4\u5219\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Go\u8bed\u8a00interface\u6548\u7387\u4f4e\uff0cGo\u4e0d\u662f\u4e3a\u8fd9\u79cd\u7a0b\u5ea6\u7684\u4f18\u5316\u8bbe\u8ba1\u7684\uff0c\u5982\u679c\u975e\u8981\u8fdb\u884c\u8fd9\u4e48micro\u7684\u4f18\u5316\uff0c\u5efa\u8bae\u4f7f\u7528C [&hellip;]","protected":false},"author":1,"featured_media":19039,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/19038"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=19038"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/19038\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/19039"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=19038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=19038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=19038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}