{"id":206923,"date":"2025-06-12T11:43:58","date_gmt":"2025-06-12T03:43:58","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206923\/"},"modified":"2025-06-12T11:43:58","modified_gmt":"2025-06-12T03:43:58","slug":"go-%e9%a1%b9%e7%9b%ae%e4%b8%ad%ef%bc%8c%e9%9d%9e%e5%85%a5%e5%8f%a3%e5%8c%85%e5%a6%82%e4%bd%95%e8%ae%bf%e9%97%ae%e5%85%84%e5%bc%9f%e5%8c%85%e5%87%bd%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206923\/","title":{"rendered":"Go \u9879\u76ee\u4e2d\uff0c\u975e\u5165\u53e3\u5305\u5982\u4f55\u8bbf\u95ee\u5144\u5f1f\u5305\u51fd\u6570\uff1f"},"content":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300aGo \u9879\u76ee\u4e2d\uff0c\u975e\u5165\u53e3\u5305\u5982\u4f55\u8bbf\u95ee\u5144\u5f1f\u5305\u51fd\u6570\uff1f\u300b\uff0c\u8986\u76d6\u4e86GOLANG\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241129\/173286076067495b581c90d.jpg\" class=\"aligncenter\">,<br \/>\n<strong>\u975e\u5165\u53e3\u5305\u8bbf\u95ee\u5144\u5f1f\u5305\u51fd\u6570\uff0c\u5b9e\u73b0\u5c0f\u5199\u51fd\u6570\u8c03\u7528<\/strong>,\u5728\u5982\u4e0b\u9879\u76ee\u7ed3\u6784\u4e2d\uff0c\u5982\u4f55\u5728 app\/blog\/router.go \u6587\u4ef6\u4e2d\u4f7f\u7528 handle.go \u91cc\u76842\u4e2a\u51fd\u6570 ahandler\u3001bhandler\uff1f,<br \/>\n<strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>,router.go\u548chandler.go\u5c5e\u4e8e\u540c\u4e00\u4e2a\u5305\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u5199 import \u5bfc\u5165\u3002\u53ef\u4ee5\u5728 router.go \u4e2d\u76f4\u63a5\u4f7f\u7528 handle.go \u4e2d\u7684\u51fd\u6570\uff0c\u5305\u62ec\u6ca1\u6709\u5f00\u5934\u5927\u5199\u5bfc\u51fa\u7684\u51fd\u6570\uff0c\u4f8b\u5982 ahandler \u548c bhandler\u3002,<br \/>\n<strong>router.go \u4ee3\u7801\uff1a<\/strong>,\u4ee5\u4e0a\u5c31\u662f\u300aGo \u9879\u76ee\u4e2d\uff0c\u975e\u5165\u53e3\u5305\u5982\u4f55\u8bbf\u95ee\u5144\u5f1f\u5305\u51fd\u6570\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff01,\u975e\u5165\u53e3\u5305\u8bbf\u95ee\u5144\u5f1f\u5305\u51fd\u6570\uff0c\u5b9e\u73b0\u5c0f\u5199\u51fd\u6570\u8c03\u7528,\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300aGo \u9879\u76ee\u4e2d\uff0c\u975e\u5165\u53e3\u5305\u5982\u4f55\u8bbf\u95ee\u5144\u5f1f\u5305\u51fd\u6570\uff1f\u300b\uff0c\u8986\u76d6\u4e86GOLANG\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002,<br \/>\n<b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>Go \u9879\u76ee\u4e2d\uff0c\u975e\u5165\u53e3\u5305\u5982\u4f55\u8bbf\u95ee\u5144\u5f1f\u5305\u51fd\u6570\uff1f<\/span><\/p>\n<h1>Go \u9879\u76ee\u4e2d\uff0c\u975e\u5165\u53e3\u5305\u5982\u4f55\u8bbf\u95ee\u5144\u5f1f\u5305\u51fd\u6570\uff1f<\/h1>\n<p><span>2024-11-29 14:12:55<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300aGo \u9879\u76ee\u4e2d\uff0c\u975e\u5165\u53e3\u5305\u5982\u4f55\u8bbf\u95ee\u5144\u5f1f\u5305\u51fd\u6570\uff1f\u300b\uff0c\u8986\u76d6\u4e86GOLANG\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241129\/173286076067495b581c90d.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u975e\u5165\u53e3\u5305\u8bbf\u95ee\u5144\u5f1f\u5305\u51fd\u6570\uff0c\u5b9e\u73b0\u5c0f\u5199\u51fd\u6570\u8c03\u7528<\/strong><\/p>\n<p>\u5728\u5982\u4e0b\u9879\u76ee\u7ed3\u6784\u4e2d\uff0c\u5982\u4f55\u5728 app\/blog\/router.go \u6587\u4ef6\u4e2d\u4f7f\u7528 handle.go \u91cc\u76842\u4e2a\u51fd\u6570 ahandler\u3001bhandler\uff1f<\/p>\n<pre>gin_demo\n\u251c\u2500\u2500 app\n\u2502   \u2514\u2500\u2500 blog\n\u2502       \u251c\u2500\u2500 handler.go\n\u2502       \u2514\u2500\u2500 router.go  \/\/ \u5982\u4f55\u5f15\u5165 handler.go \u7684\u51fd\u6570\uff1f\n\u251c\u2500\u2500 go.mod\n\u251c\u2500\u2500 go.sum\n\u251c\u2500\u2500 main.go\n\u2514\u2500\u2500 routers\n    \u2514\u2500\u2500 routers.go<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>router.go\u548chandler.go\u5c5e\u4e8e\u540c\u4e00\u4e2a\u5305\uff0c\u56e0\u6b64\u4e0d\u9700\u8981\u5199 import \u5bfc\u5165\u3002\u53ef\u4ee5\u5728 router.go \u4e2d\u76f4\u63a5\u4f7f\u7528 handle.go \u4e2d\u7684\u51fd\u6570\uff0c\u5305\u62ec\u6ca1\u6709\u5f00\u5934\u5927\u5199\u5bfc\u51fa\u7684\u51fd\u6570\uff0c\u4f8b\u5982 ahandler \u548c bhandler\u3002<\/p>\n<p><strong>router.go \u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>package blog\n\nimport (\n    \"github.com\/gin-gonic\/gin\"\n)\n\nfunc Routers(e *gin.Engine) {\n    e.GET(\"\/a\", handler.aHandler)\n    e.GET(\"\/b\", handler.bHandler)\n}<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aGo \u9879\u76ee\u4e2d\uff0c\u975e\u5165\u53e3\u5305\u5982\u4f55\u8bbf\u95ee\u5144\u5f1f\u5305\u51fd\u6570\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   win10\u600e\u4e48\u8bbe\u7f6e\u5171\u4eab\u6587\u4ef6\u5939\u53ea\u8bfb\u4e0d\u80fd\u4fee\u6539\u6743\u9650\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   React \u5b98\u7f51\u793a\u4f8b\uff1a\u904d\u5386\u6e32\u67d3\u4e2d\u7684\u7591\u95ee\u89e3\u7b54\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300aGo \u9879\u76ee\u4e2d&#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-206923","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206923","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=206923"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206923\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}