{"id":10006306,"date":"2022-08-24T15:53:34","date_gmt":"2022-08-24T07:53:34","guid":{"rendered":"https:\/\/ityet.com\/?p=10006306"},"modified":"2022-08-24T15:53:34","modified_gmt":"2022-08-24T07:53:34","slug":"golang-%e4%b8%ad%e5%8f%98%e9%87%8f%e5%ae%9a%e4%b9%89%e7%9a%84%e5%9d%91","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006306","title":{"rendered":"Golang \u4e2d\u53d8\u91cf\u5b9a\u4e49\u7684\u5751"},"content":{"rendered":"<p>\u9996\u5148\uff0c\u6587\u4ef6\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<pre><code>.\n\u251c\u2500\u2500 a\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 a.go\n\u251c\u2500\u2500 b\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 b.go\n\u251c\u2500\u2500 go.mod\n\u2514\u2500\u2500 main.go\n<\/code><\/pre>\n<p><code>a.go<\/code>:<\/p>\n<pre><code class=\"go\">package a\n\nvar Hello = &quot;a&quot;\n\nfunc NewHello() {\n    Hello = &quot;aa&quot;\n}\n<\/code><\/pre>\n<p><code>b.go<\/code>:<\/p>\n<pre><code class=\"go\">package b\n\nimport (\n    &quot;fmt&quot;\n    &quot;one\/a&quot;\n)\n\nvar World = a.Hello\n\nfunc NewWorld() {\n    fmt.Printf(World)\n}<\/code><\/pre>\n<p><code>main.go<\/code>:<\/p>\n<pre><code class=\"go\">package main\n\nimport (\n    &quot;one\/a&quot;\n    &quot;one\/b&quot;\n)\n\nfunc main() {\n    a.NewHello()\n    b.NewWorld()\n}<\/code><\/pre>\n<p>\u8fd9\u91cc\u4e3b\u8981\u7684\u95ee\u9898\u8868\u73b0\u5728<code>b.go<\/code>\u4e2d\uff0c\u672c\u8eab\u4ee5\u6211\u7684\u60f3\u6cd5\uff0c\u5728<code>main<\/code>\u4e2d\u5b9e\u4f8b\u5316\u7a0b\u5e8f\u7684\u65f6\u5019\uff0c\u9996\u5148\u5b9e\u4f8b\u5316<code>a<\/code>\uff0c\u7136\u540e\u6211\u518d\u5b9e\u4f8b\u5316<code>b<\/code>\uff0c\u90a3\u4e48\u662f\u6709\u4e2a\u5148\u540e\u987a\u5e8f\u7684\uff0c\u90a3\u4e48\u5728<code>b<\/code>\u4e2d\uff0c\u6211\u671f\u671b\u7684\u7ed3\u679c\u5e94\u8be5\u662f<code>&quot;aa&quot;<\/code>\uff0c\u5b9e\u9645\u4e0a\u6211\u5f97\u5230\u7684\u7ed3\u679c\u4f9d\u65e7\u662f<code>&quot;a&quot;<\/code>\u3002<\/p>\n<p>\u8fd9\u91cc\u5c31\u5ffd\u7565\u4e86<code>golang<\/code>\u4f5c\u4e3a\u7f16\u8bd1\u578b\u8bed\u8a00\uff0cvar\u521d\u59cb\u5316\u7684\u65f6\u5019\uff0c\u5982\u679c\u6709\u8d4b\u503c\uff0c\u90a3\u4e48\u7f16\u8bd1\u7684\u65f6\u5019\u4f1a\u76f4\u63a5\u9ed8\u8ba4\u4e3a\u5df2\u77e5\u503c\uff0c\u53e6\u5916<code>golang<\/code>\u7684\u503c\u90fd\u662f\u503c\u4f20\u9012\u65b9\u5f0f\uff0c\u800c\u5728\u7a0b\u5e8f\u8fd0\u884c\u4e2d\u4ea7\u751f\u7684\u4fee\u6539\u4e0d\u4f1a\u5bf9\u91cd\u65b0\u5b9a\u4e49\u7684\u53d8\u91cf\u8fdb\u884c\u4fee\u6539\u3002<\/p>\n<p>\u6240\u4ee5<code>b.go<\/code>\u4fee\u6539\u6210<\/p>\n<pre><code>var World = &amp;a.Hello\n\nfunc NewWorld() {\n    fmt.Printf(*World)\n}<\/code><\/pre>\n<p>\u83b7\u53d6\u539f\u53d8\u91cf\u7684\u6307\u9488\u5730\u5740\uff0c\u7136\u540e\u4ee5\u6307\u9488\u53d6\u539f\u53d8\u91cf\u7684\u6570\u636e\u503c\u5373\u53ef\u3002<\/p>\n<p>\u5176\u5b9e\u5982\u679c\u653e\u5728\u5355\u6587\u4ef6\u6765\u770b\uff0c\u4e0d\u4f1a\u72af\u8fd9\u79cd\u9519\u8bef\uff0c\u4f46\u662f\u628a\u4e24\u4e2a\u53d8\u91cf\u5b9a\u4e49\u65b9\u5f0f\u653e\u5728\u4e24\u4e2a\u72ec\u7acb\u7684\u7a0b\u5e8f\u6587\u4ef6\u540e\uff0c\u7adf\u7136\u5c31\u6ca1\u60f3\u5230\u8fd9\u4e00\u5c42\u3002<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042369450\">https:\/\/segmentfault.com\/a\/1190000042369450<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\uff0c\u6587\u4ef6\u7ed3\u6784\u5982\u4e0b\uff1a . \u251c\u2500\u2500 a \u2502\u00a0\u00a0 \u2514\u2500\u2500 a.go \u251c\u2500\u2500 b \u2502\u00a0\u00a0 \u2514\u2500\u2500 b.go \u251c\u2500\u2500  [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10006306","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006306","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"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006306"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006306\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}