{"id":206511,"date":"2025-06-12T14:12:40","date_gmt":"2025-06-12T06:12:40","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206511\/"},"modified":"2025-06-12T14:12:40","modified_gmt":"2025-06-12T06:12:40","slug":"go-%e4%b8%ad%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e7%bb%93%e6%9e%84%e4%bd%93%e5%92%8c%e7%bb%93%e6%9e%84%e4%bd%93%e6%8c%87%e9%92%88%e6%98%af%e5%90%a6%e4%b8%ba%e7%a9%ba%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206511\/","title":{"rendered":"Go \u4e2d\u5982\u4f55\u5224\u65ad\u7ed3\u6784\u4f53\u548c\u7ed3\u6784\u4f53\u6307\u9488\u662f\u5426\u4e3a\u7a7a\uff1f"},"content":{"rendered":"<p>\u5728GOLANG\u5b9e\u6218\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u8fd9\u6837\u90a3\u6837\u7684\u95ee\u9898\uff0c\u7136\u540e\u8981\u5361\u597d\u534a\u5929\uff0c\u7b49\u95ee\u9898\u89e3\u51b3\u4e86\u624d\u53d1\u73b0\u539f\u6765\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u662f\u6ca1\u6709\u638c\u63e1\u597d\u3002\u4eca\u5929GOLANG\u5c31\u6574\u7406\u5206\u4eab\u300aGo \u4e2d\u5982\u4f55\u5224\u65ad\u7ed3\u6784\u4f53\u548c\u7ed3\u6784\u4f53\u6307\u9488\u662f\u5426\u4e3a\u7a7a\uff1f\u300b\uff0c\u804a\u804a\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5230\u6b63\u5728\u52aa\u529b\u8d5a\u94b1\u7684\u4f60\u3002,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241114\/17315480296735537d15d0e.jpg\" class=\"aligncenter\">,<br \/>\n<strong>\u5982\u4f55\u5728 go \u4e2d\u533a\u5206\u7ed3\u6784\u4f53\u548c\u6307\u9488\u7684\u7a7a\u503c\uff1f<\/strong>,go \u8bed\u8a00\u4e2d\uff0c\u7ed3\u6784\u4f53\u672c\u8eab\u4e0d\u80fd\u4e3a nil\uff0c\u53ea\u6709\u5176\u6307\u9488\u53ef\u4ee5\u3002\u5f53\u58f0\u660e\u4e00\u4e2a\u7ed3\u6784\u4f53\u53d8\u91cf\u65f6\uff0c\u5176\u5b57\u6bb5\u4f1a\u81ea\u52a8\u521d\u59cb\u5316\u4e3a\u96f6\u503c\u3002,<br \/>\n<strong>\u5224\u65ad\u7a7a\u7ed3\u6784\u4f53<\/strong>,\u8981\u5224\u65ad\u4e00\u4e2a\u7ed3\u6784\u4f53\u662f\u5426\u4e3a\u7a7a\uff0c\u9700\u8981\u68c0\u67e5\u5176\u6240\u6709\u5b57\u6bb5\u7684\u503c\u662f\u5426\u4e3a\u5b83\u4eec\u7684\u521d\u59cb\u503c\uff1a,<br \/>\n<strong>\u5224\u65ad\u7a7a\u6307\u9488<\/strong>,\u5224\u65ad\u4e00\u4e2a\u7ed3\u6784\u4f53\u6307\u9488\u662f\u5426\u4e3a nil \u5f88\u7b80\u5355\uff1a,<br \/>\n<strong>\u793a\u4f8b<\/strong>,\u8f93\u51fa\uff1a,\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8eGOLANG\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~,\u5982\u4f55\u5728 go \u4e2d\u533a\u5206\u7ed3\u6784\u4f53\u548c\u6307\u9488\u7684\u7a7a\u503c\uff1f,\u5728GOLANG\u5b9e\u6218\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u8fd9\u6837\u90a3\u6837\u7684\u95ee\u9898\uff0c\u7136\u540e\u8981\u5361\u597d\u534a\u5929\uff0c\u7b49\u95ee\u9898\u89e3\u51b3\u4e86\u624d\u53d1\u73b0\u539f\u6765\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u662f\u6ca1\u6709\u638c\u63e1\u597d\u3002\u4eca\u5929GOLANG\u5c31\u6574\u7406\u5206\u4eab\u300aGo \u4e2d\u5982\u4f55\u5224\u65ad\u7ed3\u6784\u4f53\u548c\u7ed3\u6784\u4f53\u6307\u9488\u662f\u5426\u4e3a\u7a7a\uff1f\u300b\uff0c\u804a\u804a\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5230\u6b63\u5728\u52aa\u529b\u8d5a\u94b1\u7684\u4f60\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 \u4e2d\u5982\u4f55\u5224\u65ad\u7ed3\u6784\u4f53\u548c\u7ed3\u6784\u4f53\u6307\u9488\u662f\u5426\u4e3a\u7a7a\uff1f<\/span><\/p>\n<h1>Go \u4e2d\u5982\u4f55\u5224\u65ad\u7ed3\u6784\u4f53\u548c\u7ed3\u6784\u4f53\u6307\u9488\u662f\u5426\u4e3a\u7a7a\uff1f<\/h1>\n<p><span>2024-11-14 09:34:04<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5728GOLANG\u5b9e\u6218\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u8fd9\u6837\u90a3\u6837\u7684\u95ee\u9898\uff0c\u7136\u540e\u8981\u5361\u597d\u534a\u5929\uff0c\u7b49\u95ee\u9898\u89e3\u51b3\u4e86\u624d\u53d1\u73b0\u539f\u6765\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u662f\u6ca1\u6709\u638c\u63e1\u597d\u3002\u4eca\u5929GOLANG\u5c31\u6574\u7406\u5206\u4eab\u300aGo \u4e2d\u5982\u4f55\u5224\u65ad\u7ed3\u6784\u4f53\u548c\u7ed3\u6784\u4f53\u6307\u9488\u662f\u5426\u4e3a\u7a7a\uff1f\u300b\uff0c\u804a\u804a\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5230\u6b63\u5728\u52aa\u529b\u8d5a\u94b1\u7684\u4f60\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241114\/17315480296735537d15d0e.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u5728 go \u4e2d\u533a\u5206\u7ed3\u6784\u4f53\u548c\u6307\u9488\u7684\u7a7a\u503c\uff1f<\/strong><\/p>\n<p>go \u8bed\u8a00\u4e2d\uff0c\u7ed3\u6784\u4f53\u672c\u8eab\u4e0d\u80fd\u4e3a nil\uff0c\u53ea\u6709\u5176\u6307\u9488\u53ef\u4ee5\u3002\u5f53\u58f0\u660e\u4e00\u4e2a\u7ed3\u6784\u4f53\u53d8\u91cf\u65f6\uff0c\u5176\u5b57\u6bb5\u4f1a\u81ea\u52a8\u521d\u59cb\u5316\u4e3a\u96f6\u503c\u3002<\/p>\n<p><strong>\u5224\u65ad\u7a7a\u7ed3\u6784\u4f53<\/strong><\/p>\n<p>\u8981\u5224\u65ad\u4e00\u4e2a\u7ed3\u6784\u4f53\u662f\u5426\u4e3a\u7a7a\uff0c\u9700\u8981\u68c0\u67e5\u5176\u6240\u6709\u5b57\u6bb5\u7684\u503c\u662f\u5426\u4e3a\u5b83\u4eec\u7684\u521d\u59cb\u503c\uff1a<\/p>\n<pre>type product struct {\n    name, category string\n    price          float64\n    upc            int64\n}\n\nfunc isproductempty(p product) bool {\n    return p.name == \"\" &amp;&amp; p.category == \"\" &amp;&amp; p.price == 0 &amp;&amp; p.upc == 0\n}<\/pre>\n<p><strong>\u5224\u65ad\u7a7a\u6307\u9488<\/strong><\/p>\n<p>\u5224\u65ad\u4e00\u4e2a\u7ed3\u6784\u4f53\u6307\u9488\u662f\u5426\u4e3a nil \u5f88\u7b80\u5355\uff1a<\/p>\n<pre>var prdptr *product\n\nif prdptr == nil {\n    \/\/ \u6307\u9488\u4e3a\u7a7a\n}<\/pre>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<pre>package main\n\nimport \"fmt\"\n\ntype product struct {\n   name, category string\n   price          float64\n   upc            int64\n}\n\nfunc main() {\n   var prd product\n   var prdptr *product\n\n   fmt.println(\"\u503c:\", prd.name, prd.category, prd.price)\n   fmt.println(\"\u6307\u9488:\", prdptr)\n\n   if isproductempty(prd) {\n       fmt.println(\"\u7ed3\u6784\u4f53\u4e3a\u7a7a\")\n   } else {\n       fmt.println(\"\u7ed3\u6784\u4f53\u4e0d\u4e3a\u7a7a\")\n   }\n\n   if prdptr == nil {\n       fmt.println(\"\u6307\u9488\u4e3a\u7a7a\")\n   } else {\n       fmt.println(\"\u6307\u9488\u4e0d\u4e3a\u7a7a\")\n   }\n}<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>\u503c:  0\n\u6307\u9488: &lt;nil&gt;\n\u7ed3\u6784\u4f53\u4e3a\u7a7a\n\u6307\u9488\u4e3a\u7a7a<\/pre>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8eGOLANG\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u5982\u4f55\u5728 Java \u4e2d\u4f18\u5316\u591a\u4e2a\u6761\u4ef6\u7684\u9012\u8fdb\u5f0f\u5224\u65ad\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   React \u5237\u65b0\u6d4f\u89c8\u5668\u9875\u9762\u62a5 404 \u9519\u8bef\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5728GOLANG\u5b9e\u6218\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c&#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-206511","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206511","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=206511"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206511\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}