{"id":950,"date":"2024-11-07T08:22:43","date_gmt":"2024-11-07T00:22:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/950\/"},"modified":"2024-11-07T08:22:43","modified_gmt":"2024-11-07T00:22:43","slug":"go-%e4%b8%ad%e8%b7%a8%e5%ad%90%e5%8c%85%e8%b0%83%e7%94%a8%e6%96%b9%e6%b3%95%e6%97%b6%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e5%be%aa%e7%8e%af%e5%af%bc%e5%85%a5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/950\/","title":{"rendered":"Go \u4e2d\u8de8\u5b50\u5305\u8c03\u7528\u65b9\u6cd5\u65f6\u5982\u4f55\u907f\u514d\u5faa\u73af\u5bfc\u5165\uff1f"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-961\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173090414058569.jpg\" width=\"800\" height=\"320\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173090414058569.jpg 800w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173090414058569-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173090414058569-768x307.jpg 768w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173090414058569-670x268.jpg 670w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" title=\"Go \u4e2d\u8de8\u5b50\u5305\u8c03\u7528\u65b9\u6cd5\u65f6\u5982\u4f55\u907f\u514d\u5faa\u73af\u5bfc\u5165\uff1f\u63d2\u56fe\" alt=\"Go \u4e2d\u8de8\u5b50\u5305\u8c03\u7528\u65b9\u6cd5\u65f6\u5982\u4f55\u907f\u514d\u5faa\u73af\u5bfc\u5165\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>go \u4e2d\u8de8\u5b50\u5305\u8c03\u7528\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728 go \u4e2d\uff0c\u5f53\u5728\u5b50\u5305\u4e2d\u5b9a\u4e49\u65b9\u6cd5\u5e76\u8bd5\u56fe\u4ece\u4e3b\u5305\u8c03\u7528\u65f6\uff0c\u5982\u679c\u5bfc\u5165\u5b58\u5728\u5faa\u73af\u5f15\u7528\uff0c\u7f16\u8bd1\u5668\u4f1a\u62a5\u9519\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a\u5faa\u73af\u5bfc\u5165\u5bfc\u81f4\u7684\u9519\u8bef<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u5728\u5b50\u5305\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e9b\u65b9\u6cd5\uff0c\u5e76\u5728\u4e3b\u5305\u4e2d\u5c1d\u8bd5\u5bf9\u5176\u8fdb\u884c\u5bfc\u5165\uff0c\u4f46\u7f16\u8bd1\u65f6\u63d0\u793a &#8220;import cycle not allowed&#8221; \u9519\u8bef\uff0c\u8fd9\u8868\u660e\u5b58\u5728\u5305\u5bfc\u5165\u5faa\u73af\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a\u907f\u514d\u5faa\u73af\u5bfc\u5165<\/strong><\/p>\n<p>\u6b64\u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6848\u662f\u907f\u514d\u5faa\u73af\u5bfc\u5165\u3002\u60a8\u65e0\u6cd5\u5728 a \u5305\u4e2d\u5bfc\u5165 b \u5305\uff0c\u7136\u540e\u518d\u5728 b \u5305\u4e2d\u5bfc\u5165 a \u5305\u3002<\/p>\n<p>\u4e00\u4e2a\u5e38\u89c1\u7684\u539f\u56e0\u662f\uff0c\u6bcf\u4e2a\u5b50\u5305\u90fd\u5c1d\u8bd5\u5bfc\u5165\u5176 parent \u5305\u3002\u5728\u60a8\u7684\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u5728 parent \u5305\u4e2d\u5b9a\u4e49\u8981\u4ece\u5b50\u5305\u8c03\u7528\u7684\u65b9\u6cd5\uff0c\u800c\u5b50\u5305\u53ea\u5bfc\u5165 parent \u5305\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>\/\/ parent\/foo.go\npackage parent\n\n\/\/ a \u63d0\u4f9b\u4e00\u4e2a\u901a\u7528\u65b9\u6cd5\nfunc a() {\n    fmt.println(\"a\")\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<pre>\/\/ child\/bar.go\npackage child\n\nimport \"parent\"\n\n\/\/ B \u4f7f\u7528 A \u65b9\u6cd5\nfunc B() {\n    parent.A()\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0cchild \u5305\u53ef\u4ee5\u8c03\u7528 parent \u5305\u4e2d\u7684 a \u65b9\u6cd5\uff0c\u800c\u4e0d\u4f1a\u5bfc\u81f4\u5faa\u73af\u5bfc\u5165\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<p>\u60a8\u63d0\u5230\u7684\u6587\u7ae0\u94fe\u63a5\u5df2\u5305\u542b\u6b64\u5904\u63d0\u4f9b\u7684\u76f8\u540c\u4fe1\u606f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fGo \u4e2d\u8de8\u5b50\u5305\u8c03\u7528\u65b9\u6cd5\u65f6\u5982\u4f55\u907f\u514d\u5faa\u73af\u5bfc\u5165\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>go \u4e2d\u8de8\u5b50\u5305\u8c03\u7528\u65b9\u6cd5 \u5728 go \u4e2d\uff0c\u5f53\u5728\u5b50\u5305\u4e2d\u5b9a\u4e49\u65b9\u6cd5\u5e76\u8bd5\u56fe\u4ece\u4e3b\u5305\u8c03\u7528\u65f6\uff0c\u5982\u679c\u5bfc\u5165\u5b58\u5728\u5faa\u73af\u5f15\u7528\uff0c\u7f16\u8bd1\u5668\u4f1a\u62a5\u9519\u3002 \u95ee\u9898\uff1a\u5faa\u73af\u5bfc\u5165\u5bfc\u81f4\u7684\u9519\u8bef \u5982\u679c\u60a8\u5728\u5b50\u5305\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e9b\u65b9\u6cd5\uff0c\u5e76\u5728\u4e3b\u5305\u4e2d\u5c1d\u8bd5\u5bf9\u5176\u8fdb\u884c\u5bfc\u5165\uff0c\u4f46\u7f16\u8bd1\u65f6\u63d0\u793a &#8220;import cycle not allowed&#8221; \u9519\u8bef\uff0c\u8fd9\u8868\u660e\u5b58\u5728\u5305\u5bfc\u5165\u5faa\u73af\u3002 \u89e3\u51b3\u65b9\u6848\uff1a\u907f\u514d\u5faa\u73af\u5bfc\u5165 \u6b64\u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6848\u662f\u907f\u514d\u5faa\u73af\u5bfc\u5165\u3002\u60a8\u65e0\u6cd5\u5728 a \u5305\u4e2d\u5bfc\u5165 b \u5305\uff0c\u7136\u540e\u518d\u5728 b \u5305\u4e2d\u5bfc\u5165 a \u5305\u3002 \u4e00\u4e2a\u5e38\u89c1\u7684\u539f\u56e0\u662f\uff0c\u6bcf\u4e2a\u5b50\u5305\u90fd\u5c1d\u8bd5\u5bfc\u5165\u5176 parent \u5305\u3002\u5728\u60a8\u7684\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u5728 parent \u5305\u4e2d\u5b9a\u4e49\u8981\u4ece\u5b50\u5305\u8c03\u7528\u7684\u65b9\u6cd5\uff0c\u800c\u5b50\u5305\u53ea\u5bfc\u5165 parent \u5305\u3002 \u4f8b\u5982\uff1a \/\/ parent\/foo.go package parent \/\/ a \u63d0\u4f9b\u4e00\u4e2a\u901a\u7528\u65b9\u6cd5 func a() { fmt.println(&#8220;a&#8221;) } \u767b\u5f55\u540e\u590d\u5236 \/\/ child\/bar.go package child import &#8220;parent&#8221; \/\/ B \u4f7f\u7528 A \u65b9\u6cd5 func [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-950","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=950"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/950\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}