{"id":10006545,"date":"2022-09-20T13:40:27","date_gmt":"2022-09-20T05:40:27","guid":{"rendered":"https:\/\/ityet.com\/?p=10006545"},"modified":"2022-09-20T13:40:27","modified_gmt":"2022-09-20T05:40:27","slug":"go-%e4%bb%a3%e7%a0%81%e9%a3%8e%e6%a0%bc%e6%b2%a1%e4%ba%ba%e5%96%9c%e6%ac%a2%ef%bc%9f%e4%b8%8d%e5%af%b9%ef%bc%8cgofmt-%e6%98%af%e6%89%80%e6%9c%89%e4%ba%ba%e7%9a%84%e6%9c%80%e7%88%b1","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006545","title":{"rendered":"Go \u4ee3\u7801\u98ce\u683c\u6ca1\u4eba\u559c\u6b22\uff1f\u4e0d\u5bf9\uff0cGofmt \u662f\u6240\u6709\u4eba\u7684\u6700\u7231&#8230;"},"content":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u714e\u9c7c\u3002<\/p>\n<p>\u5728\u4efb\u4f55\u8bed\u8a00\u8fdb\u884c\u7f16\u7a0b\u5f00\u53d1\u65f6\uff0c\u53ea\u8981\u6d89\u53ca\u5230\u591a\u4eba\u534f\u4f5c\u3002\u5c31\u4e00\u5b9a\u4f1a\u9047\u5230\u4e00\u4e2a\u65f7\u4e16\u6597\u4e89\u7684\u5927\u95ee\u9898\u3002\u90a3\u5c31\u662f\uff1a\u7f16\u7801\u98ce\u683c\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042514756\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>Go \u7684\uff0cPHP \u7684\uff0cJava \u7684\uff0cC++ \u7684\uff1b\u521d\u7ea7\u3001\u4e2d\u7ea7\u3001\u9ad8\u7ea7\u3001\u7ba1\u7406\u7684\u98ce\u683c\uff1b\u4f20\u7edf\u7684\u3001\u4e92\u8054\u7f51\u7684\u53c8\u90fd\u4e0d\u4e00\u6837\u3002<\/p>\n<h2>\u8c01\u7684\u98ce\u683c\u66f4\u597d<\/h2>\n<p>\u4f8b\u5982\u7ecf\u5178\u7684\u5224\u65ad\u573a\u666f\uff1aif err != nil \uff0c\u81f3\u5c11\u53ef\u4ee5\u5199\u51fa\u4e09\u79cd\u6a21\u5f0f\u3002\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"go\"># \u65b9\u5f0f\u4e00\nif err != nil {\n  \/\/ do something...\n}\n\n# \u65b9\u5f0f\u4e8c\nif err != nil\n{\n  \/\/ do something...\n}\n\n# \u65b9\u5f0f\u4e09\nif err != nil { \/\/ do something... }<\/code><\/pre>\n<p>\u5728\u56e2\u961f\u4e2d\uff0c\u5230\u5e95\u9009\u7528\u54ea\u4e00\u79cd\u65b9\u5f0f\u5462\uff1f\u770b\u6027\u80fd\uff1f\u770b\u98ce\u683c\uff1f\u770b\u5c11\u6253\u51e0\u4e2a\u7a7a\u683c\uff1f\u770b\u8c01\u62f3\u5934\u5927\uff1f<\/p>\n<p>\u8fd9\u662f\u4e2a\u7ecf\u5e38\u660e\u7684\u6697\u91cc\u6495\u903c\u7684\u95ee\u9898\u3002<\/p>\n<h2>\u7edf\u4e00\u7f16\u7801\u98ce\u683c<\/h2>\n<p>\u5728 Go \u7684\u8c1a\u8bed\u4e2d\u6709\u4e00\u53e5\u662f\uff1a\u201cGofmt\u2019s style is no one\u2019s favorite, yet gofmt is everyone\u2019s favorite\u201d\u3002\u5927\u81f4\u7684\u610f\u601d\u662f Gofmt \u7684\u98ce\u683c\u6ca1\u6709\u4eba\u559c\u6b22\uff0c\u4f46 Gofmt \u662f\u6bcf\u4e2a\u4eba\u7684\u6700\u7231\u3002<\/p>\n<p>\u8fd9\u662f\u4e3a\u4ec0\u4e48\u5462\uff1f\u53c8\u7231\u53c8\u4e0d\u7231\u7684\u3002<\/p>\n<p>\u6211\u4eec\u5148\u4ece Gofmt \u7684\u529f\u80fd\u6765\u8bb2\uff0c\u5b83\u80fd\u591f\u683c\u5f0f\u5316 Go \u7a0b\u5e8f\uff0c\u4f7f\u7528\u5236\u8868\u7b26\u6765\u7f29\u8fdb\uff0c\u4f7f\u7528\u7a7a\u683c\u6765\u5bf9\u9f50\uff0c\u80fd\u591f\u8ba9\u4f60\u7684\u4ee3\u7801\u957f\u7684\u90fd\u4e00\u6837\u3002<\/p>\n<p>\u65e0\u8bba\u662f\u8c01\uff0c\u600e\u4e48\u5199\u3002\u53ea\u8981\u7ed3\u5408 IDE \u548c Gofmt \u4e00\u914d\u7f6e\uff0c\u90fd\u4f1a\u53d8\u6210\u5982\u4e0b\u683c\u5f0f\uff1a<\/p>\n<pre><code class=\"go\">if err != nil {\n  \/\/ do something...\n}<\/code><\/pre>\n<p>\u56e0\u6b64\u5728 Go \u4e2d\uff0c\u7f16\u7801\u98ce\u683c\u7684\u4e89\u8bae\u53d8\u5f97\u6beb\u65e0\u610f\u4e49\u3002\u7531\u5b98\u65b9\u7edf\u4e00\u7ba1\u63a7\uff0c\u82e5\u6709\u77db\u76fe\u4e5f\u4f1a\u8f6c\u79fb\u5230 Go \u56e2\u961f\u672c\u8eab\u3002<\/p>\n<p>\u7efc\u5408\u6765\u770b\uff0c\u5927\u5bb6\u8fd8\u662f\u4f1a\u66f4\u503e\u5411\u4e8e\u5f80\u5b98\u65b9\u5b9a\u4e49\u7684\u98ce\u683c\u53bb\u9760\u8fd1\uff0c\u53bb\u7b26\u5408\u6807\u51c6\uff0c\u80fd\u591f\u51cf\u5c11\u975e\u5e38\u591a\u7684\u4e89\u7aef\u3002<\/p>\n<p>\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48 \u201dGofmt \u662f\u6bcf\u4e2a\u4eba\u7684\u6700\u7231\u201c \u7684\u539f\u56e0\u4e86\uff0c\u5f53\u7136\u3002\u6211\u8ba4\u4e3a\u53eb \u201d\u56e2\u961f\u7684\u6700\u7231\u201c \u53ef\u80fd\u66f4\u52a0\u7684\u9002\u5408\u3002<\/p>\n<h2>\u6ca1\u6709\u65bd\u5c55\u7a7a\u95f4<\/h2>\n<p>\u8c1a\u8bed\u91cc\u4e5f\u63d0\u5230\u4e86\uff0cGofmt \u7684\u98ce\u683c\u6ca1\u6709\u4eba\u559c\u6b22\u3002\u8fd9\u53c8\u600e\u4e48\u8bf4\uff1f<\/p>\n<p>\u771f\u5b9e\u7684\u793e\u533a\u670b\u53cb\u4f1a\u9047\u5230\u8fd9\u7c7b\u573a\u666f\u3002\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042514757\" alt=\"\u6765\u81ea\u9c7c\u7c89\u7684\u5fae\u4fe1\u54a8\u8be2\" title=\"\u6765\u81ea\u9c7c\u7c89\u7684\u5fae\u4fe1\u54a8\u8be2\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042514758\" alt=\"\u6765\u81ea\u9c7c\u7c89\u7684\u5fae\u4fe1\u54a8\u8be2\" title=\"\u6765\u81ea\u9c7c\u7c89\u7684\u5fae\u4fe1\u54a8\u8be2\" loading=\"lazy\"><\/p>\n<p>\u5b9e\u9645\u4e0a Gofmt \u6709\u4e0d\u5c11\u5bf9\u9f50\u6709\u7684\u5c0f\u4f19\u4f34\u5e76\u4e0d\u559c\u6b22\uff0c\u60f3\u6539\u3002\u5f88\u53ef\u60dc&#8230;\u5e76\u4e0d\u80fd\uff0cGo \u5c31\u662f\u8981\u5b8c\u5168\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<p>\u751a\u81f3\u6709\u540c\u5b66\u5728\u793e\u533a issues \u63d0\u8fc7\uff0cGo \u6838\u5fc3\u56e2\u961f\u7684 rsc \u4e5f\u7ed9\u51fa\u4e86\u660e\u786e\u7684\u76f4\u63a5\u56de\u590d\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042514759\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5bf9\u4e8e Go \u7684\u8bbe\u8ba1\u6765\u8bb2\uff0cGofmt \u6ca1\u6709\u914d\u7f6e\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u5982\u679c\u60f3\u8981\u589e\u52a0\u53ef\u914d\u7f6e\u7684\u89c4\u8303\u5316\uff0c\u8fd9\u662f\u4e0d\u53ef\u80fd\u7684\u3002<\/p>\n<p>\u8c1a\u8bed\u8bf4\u5230 Gofmt \u6ca1\u6709\u4eba\u559c\u6b22\uff0c\u4e5f\u662f\u56e0\u4e3a\u5b83\u662f\u4e00\u4e2a\u5f3a\u5236\u6027\u7684\u4e1c\u897f\uff0c\u4e0d\u5173\u4e4e\u4f60\u7684\u559c\u597d\u4e0e\u5426\uff0c\u603b\u6709\u4eba\u559c\u6b22\u4e0d\u4e00\u6837\u7684\u89c4\u8303\u683c\u5f0f\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>Go \u7f16\u7a0b\u89c4\u8303\u7684\u6807\u51c6\u7edf\u4e00\u5316\uff0c\u4ece\u4e0d\u540c\u7684\u89d2\u5ea6\u6765\u770b\u6709\u597d\u6709\u574f\u3002\u4f46\u5f53\u4f60\u63a5\u53d7\u4e00\u4e2a\u5386\u53f2\u65b0\u4ee3\u7801\uff0c\u5b83\u7684\u7f16\u7801\u683c\u5f0f\u90fd\u88ab Gofmt \u5904\u7406\u7684\u6574\u6574\u9f50\u9f50\uff0c\u548c\u4f60 10 \u5e74\u540e\u770b\u5230\u7684\u4ee3\u7801\u683c\u5f0f\u4f9d\u7136\u4e00\u81f4\uff0c\u90a3\u4e5f\u786e\u5b9e\u662f\u4e00\u4e2a\u5f88\u4e0d\u9519\u7684\u76ca\u5904\u3002<\/p>\n<p>\u8bed\u8a00\u672c\u8eab\u6765\u770b\uff0c\u5b83\u662f\u8ba9 Go \u6210\u529f\u7684\u91cd\u8981\u539f\u56e0\u4e4b\u4e00\uff0c\u8ba9\u8bb8\u591a\u56e2\u961f\u8bb8\u591a\u4eba\u51cf\u5c11\u4e86\u5f88\u591a\u4e89\u7aef\uff0c\u529f\u5927\u4e8e\u8fc7\uff0c\u6709\u76f8\u5f53\u7684\u5b58\u5728\u5fc5\u8981\u3002\u4f60\u8ba4\u4e3a\u5462\uff1f<\/p>\n<blockquote><p>\u6587\u7ae0\u6301\u7eed\u66f4\u65b0\uff0c\u53ef\u4ee5\u5fae\u4fe1\u641c\u3010\u8111\u5b50\u8fdb\u714e\u9c7c\u4e86\u3011\u9605\u8bfb\uff0c\u672c\u6587 <strong>GitHub<\/strong> <a href=\"https:\/\/link.segmentfault.com\/?enc=97qLtjhKILlM3y4Gfh4m0A%3D%3D.w%2BKuYfII%2BgAZMXhvN%2BEDAheIvdmFgTVlH2JGBBwENiQ%3D\" rel=\"nofollow\">github.com\/eddycjy\/blog<\/a> \u5df2\u6536\u5f55\uff0c\u5b66\u4e60 Go \u8bed\u8a00\u53ef\u4ee5\u770b <a href=\"https:\/\/link.segmentfault.com\/?enc=xnbQaVIJYNvuTy2E3wgZ%2Bg%3D%3D.R%2FtnVZK5vw%2FwmofcCdXuN5i%2FDo95EnDFBUtqhgnUNClOlENtHF0N1hcp93RPFtL1\" rel=\"nofollow\">Go \u5b66\u4e60\u5730\u56fe\u548c\u8def\u7ebf<\/a>\uff0c\u6b22\u8fce Star \u50ac\u66f4\u3002<\/p><\/blockquote>\n<h3>Go \u56fe\u4e66\u7cfb\u5217<\/h3>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=rWTK5SVssREu3osKlv%2Bb1A%3D%3D.QdVwFATpVCl2jLmWMHn5lqrw1qFlQ636Rp1T4DMJ%2FyhEauL05ntGs6ZGdns%2B7aCz\" rel=\"nofollow\">Go \u8bed\u8a00\u5165\u95e8\u7cfb\u5217\uff1a\u521d\u63a2 Go \u9879\u76ee\u5b9e\u6218<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=E%2FYgOsLce3xKtgvLatgUSg%3D%3D.f1IDZ%2BtoHUjDiqb4D2CkGLrr9f6ydFtVIUVm3wyoOaw%3D\" rel=\"nofollow\">Go \u8bed\u8a00\u7f16\u7a0b\u4e4b\u65c5\uff1a\u6df1\u5165\u7528 Go \u505a\u9879\u76ee<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=uxc66LIu%2F9WrEergVVS5Rg%3D%3D.mQdDf4%2FNDuPFvA%2BApR%2BpsJRUpnfg9nBh7FLSTQPqJlw%3D\" rel=\"nofollow\">Go \u8bed\u8a00\u8bbe\u8ba1\u54f2\u5b66\uff1a\u4e86\u89e3 Go \u7684\u4e3a\u4ec0\u4e48\u548c\u8bbe\u8ba1\u601d\u8003<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=3Az5VNHC4mPBKr5cQ8xCfg%3D%3D.tlE7wSJf0d00L0nCQBAJYZFcBp30NDrqueNlAL7MU6k%3D\" rel=\"nofollow\">Go \u8bed\u8a00\u8fdb\u9636\u4e4b\u65c5\uff1a\u8fdb\u4e00\u6b65\u6df1\u5165 Go \u6e90\u7801<\/a><\/li>\n<\/ul>\n<h3>\u63a8\u8350\u9605\u8bfb<\/h3>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=nAFvoYk6J4wev%2Fy0qKpQpg%3D%3D.paZQxXwBoaTuJnxsMOcpjWfQTPa%2BDCfqZeZdncAPw0TgQIBFhkGha2qQJYXZggVyl%2FYv8ohB9ylZogKijPOWMQ%3D%3D\" rel=\"nofollow\">goto \u8bed\u53e5\u8ba9 Go \u4ee3\u7801\u53d8\u6210\u610f\u5927\u5229\u9762\u6761\uff1f<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=45EW1QbpAF7tJ7saQ3I3hA%3D%3D.v%2FqfpZsLp5LhcLU8CFdtGJvV96x9UMwLjgf5KoYr6FkX7qciHTUcv%2F8F22qR9ip2Glw8Ns4Vn7aX3JB0SmVLSw%3D%3D\" rel=\"nofollow\">Go \u53ea\u4f1a if err != nil\uff1f\u8fd9\u662f\u4e0d\u5bf9\u7684\uff0c\u5206\u4eab\u8fd9\u4e9b\u4f18\u96c5\u7684\u5904\u7406\u59ff\u52bf\u7ed9\u4f60\uff01<\/a><\/li>\n<\/ul>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042514754\">https:\/\/segmentfault.com\/a\/1190000042514754<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u714e\u9c7c\u3002 \u5728\u4efb\u4f55\u8bed\u8a00\u8fdb\u884c\u7f16\u7a0b\u5f00\u53d1\u65f6\uff0c\u53ea\u8981\u6d89\u53ca\u5230\u591a\u4eba\u534f\u4f5c\u3002\u5c31\u4e00\u5b9a\u4f1a\u9047\u5230\u4e00\u4e2a\u65f7\u4e16\u6597\u4e89\u7684\u5927\u95ee\u9898\u3002\u90a3\u5c31\u662f\uff1a\u7f16 [&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-10006545","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\/10006545","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=10006545"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006545\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}