{"id":205522,"date":"2025-06-12T10:55:50","date_gmt":"2025-06-12T02:55:50","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205522\/"},"modified":"2025-06-12T10:55:50","modified_gmt":"2025-06-12T02:55:50","slug":"golang-%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e8%bf%9b%e8%a1%8c%e5%8c%bf%e5%90%8d%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205522\/","title":{"rendered":"Golang \u51fd\u6570\u5982\u4f55\u8fdb\u884c\u533f\u540d\u7c7b\u578b"},"content":{"rendered":"<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGOLANG \u51fd\u6570\u5982\u4f55\u8fdb\u884c\u533f\u540d\u7c7b\u578b\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01,\u53ef\u4ee5\u4f7f\u7528\u533f\u540d\u7c7b\u578b\u6784\u5efa GOLANG \u51fd\u6570\uff0c\u800c\u4e0d\u7528\u663e\u5f0f\u58f0\u660e\u4e00\u4e2a struct\u3002\u8bed\u6cd5\uff1afuncName(param1 type1, param2 type2, &#8230;) (returnType1, returnType2, &#8230;)\u3002\u5b9e\u6218\uff1a\u521b\u5efa\u51fd\u6570 printPerson\uff0c\u63a5\u6536\u533f\u540d\u7c7b\u578b\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u6253\u5370\u5176\u5b57\u6bb5\uff1afunc printPerson(person struct { name string; age int })\u3002,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729918898671c77b258950.jpg\" class=\"aligncenter\">,<br \/>\n<strong>\u4f7f\u7528\u533f\u540d\u7c7b\u578b\u6784\u5efa GOLANG \u51fd\u6570<\/strong>,\u533f\u540d\u7c7b\u578b\u662f GOLANG \u4e2d\u4e00\u4e2a\u5f3a\u5927\u7684\u7279\u6027\uff0c\u5b83\u5141\u8bb8\u60a8\u521b\u5efa\u533f\u540d\u7c7b\u578b\uff0c\u800c\u4e0d\u7528\u663e\u5f0f\u58f0\u660e\u4e00\u4e2a struct\u3002\u8fd9\u5728\u533f\u540d\u51fd\u6570\u6216\u4f5c\u4e3a\u65b9\u6cd5\u7684\u63a5\u6536\u5668\u7c7b\u578b\u65f6\u5f88\u6709\u7528\u3002,<br \/>\n<strong>\u8bed\u6cd5<\/strong>,\u533f\u540d\u7c7b\u578b\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a,\u5176\u4e2d\uff1a,<br \/>\n<strong>\u5b9e\u6218\u6848\u4f8b<\/strong>,\u521b\u5efa\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u533f\u540d\u7c7b\u578b\u7684\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u6253\u5370\u5176\u5b57\u6bb5\uff1a,\u8fd0\u884c\u7a0b\u5e8f\u8f93\u51fa\uff1a,<br \/>\n<strong>\u6ce8\u610f\uff1a<\/strong>,\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aGOLANG \u51fd\u6570\u5982\u4f55\u8fdb\u884c\u533f\u540d\u7c7b\u578b\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u5427\uff01,\u53ef\u4ee5\u4f7f\u7528<br \/>\n<code>*<\/code> \u6307\u9488\u7c7b\u578b\u6765\u63a5\u6536\u533f\u540d\u7684struct\u3002,\u533f\u540d\u7c7b\u578b\u53ef\u4ee5\u5b9e\u73b0\u63a5\u53e3\u3002,\u533f\u540d\u7c7b\u578b\u53ea\u80fd\u5728\u51fd\u6570\u4f5c\u7528\u57df\u5185\u4f7f\u7528\u3002,<br \/>\n<code>returnType1<\/code>,<br \/>\n<code>returnType2<\/code> \u7b49\u8fd4\u56de\u7c7b\u578b\u662f\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u3002,<br \/>\n<code>param1<\/code>,<br \/>\n<code>param2<\/code> \u7b49\u53c2\u6570\u7c7b\u578b\u662f\u533f\u540d\u7c7b\u578b\u7684\u5b57\u6bb5\u3002,\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGOLANG \u51fd\u6570\u5982\u4f55\u8fdb\u884c\u533f\u540d\u7c7b\u578b\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<br \/>\n<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01,<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>GOLANG \u51fd\u6570\u5982\u4f55\u8fdb\u884c\u533f\u540d\u7c7b\u578b<\/span><\/p>\n<h1>GOLANG \u51fd\u6570\u5982\u4f55\u8fdb\u884c\u533f\u540d\u7c7b\u578b<\/h1>\n<p><span>2024-10-26 13:01:53<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aGOLANG \u51fd\u6570\u5982\u4f55\u8fdb\u884c\u533f\u540d\u7c7b\u578b\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">GOLANG<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u533f\u540d\u7c7b\u578b\u6784\u5efa GOLANG \u51fd\u6570\uff0c\u800c\u4e0d\u7528\u663e\u5f0f\u58f0\u660e\u4e00\u4e2a struct\u3002\u8bed\u6cd5\uff1afuncName(param1 type1, param2 type2, &#8230;) (returnType1, returnType2, &#8230;)\u3002\u5b9e\u6218\uff1a\u521b\u5efa\u51fd\u6570 printPerson\uff0c\u63a5\u6536\u533f\u540d\u7c7b\u578b\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u6253\u5370\u5176\u5b57\u6bb5\uff1afunc printPerson(person struct { name string; age int })\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729918898671c77b258950.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u4f7f\u7528\u533f\u540d\u7c7b\u578b\u6784\u5efa GOLANG \u51fd\u6570<\/strong><\/p>\n<p>\u533f\u540d\u7c7b\u578b\u662f GOLANG \u4e2d\u4e00\u4e2a\u5f3a\u5927\u7684\u7279\u6027\uff0c\u5b83\u5141\u8bb8\u60a8\u521b\u5efa\u533f\u540d\u7c7b\u578b\uff0c\u800c\u4e0d\u7528\u663e\u5f0f\u58f0\u660e\u4e00\u4e2a struct\u3002\u8fd9\u5728\u533f\u540d\u51fd\u6570\u6216\u4f5c\u4e3a\u65b9\u6cd5\u7684\u63a5\u6536\u5668\u7c7b\u578b\u65f6\u5f88\u6709\u7528\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<p>\u533f\u540d\u7c7b\u578b\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>func funcName(param1 type1, param2 type2, ...) (returnType1, returnType2, ...) {\n  \/\/ \u51fd\u6570\u4f53\n}<\/pre>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li><code>param1<\/code>, <code>param2<\/code> \u7b49\u53c2\u6570\u7c7b\u578b\u662f\u533f\u540d\u7c7b\u578b\u7684\u5b57\u6bb5\u3002<\/li>\n<li><code>returnType1<\/code>, <code>returnType2<\/code> \u7b49\u8fd4\u56de\u7c7b\u578b\u662f\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u533f\u540d\u7c7b\u578b\u7684\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u6253\u5370\u5176\u5b57\u6bb5\uff1a<\/p>\n<pre>package main\n\nimport \"fmt\"\n\nfunc main() {\n  \/\/ \u521b\u5efa\u533f\u540d\u7c7b\u578b\n  person := struct {\n    name string\n    age  int\n  }{\n    name: \"John Doe\",\n    age:  30,\n  }\n\n  \/\/ \u5c06\u533f\u540d\u5bf9\u8c61\u4f20\u9012\u7ed9\u51fd\u6570\n  printPerson(person)\n}\n\n\/\/ \u63a5\u6536\u533f\u540d\u7c7b\u578b\u4f5c\u4e3a\u53c2\u6570\u7684\u51fd\u6570\nfunc printPerson(person struct {\n  name string\n  age  int\n}) {\n  fmt.Printf(\"Name: %s\\n\", person.name)\n  fmt.Printf(\"Age: %d\\n\", person.age)\n}<\/pre>\n<p>\u8fd0\u884c\u7a0b\u5e8f\u8f93\u51fa\uff1a<\/p>\n<pre>Name: John Doe\nAge: 30<\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u533f\u540d\u7c7b\u578b\u53ea\u80fd\u5728\u51fd\u6570\u4f5c\u7528\u57df\u5185\u4f7f\u7528\u3002<\/li>\n<li>\u533f\u540d\u7c7b\u578b\u53ef\u4ee5\u5b9e\u73b0\u63a5\u53e3\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528 <code>*<\/code> \u6307\u9488\u7c7b\u578b\u6765\u63a5\u6536\u533f\u540d\u7684struct\u3002<\/li>\n<\/ul>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aGOLANG \u51fd\u6570\u5982\u4f55\u8fdb\u884c\u533f\u540d\u7c7b\u578b\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u5427\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u5982\u4f55\u901a\u8fc7\u57fa\u51c6\u6d4b\u8bd5\u5ea6\u91cf\u548c\u6539\u8fdb Java \u51fd\u6570\u6027\u80fd\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   golang\u6846\u67b6\u4ee3\u7801\u751f\u6210\u7684\u6700\u4f73\u5b9e\u8df5\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86 &#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-205522","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205522","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=205522"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205522\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}