{"id":10005990,"date":"2022-07-22T11:58:40","date_gmt":"2022-07-22T03:58:40","guid":{"rendered":"https:\/\/ityet.com\/?p=10005990"},"modified":"2022-07-22T11:58:40","modified_gmt":"2022-07-22T03:58:40","slug":"go-%e5%b8%b8%e9%87%8f%e5%8f%aa%e6%94%af%e6%8c%81%e5%9f%ba%e6%9c%ac%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%ef%bc%9f%e4%b8%ba%e4%bb%80%e4%b9%88%ef%bc%9f%e7%a4%be%e5%8c%ba%e6%92%95%e4%ba%86-9-%e5%b9%b4","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10005990","title":{"rendered":"Go \u5e38\u91cf\u53ea\u652f\u6301\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff1f\u4e3a\u4ec0\u4e48\uff1f\u793e\u533a\u6495\u4e86 9 \u5e74\u4e86&#8230;"},"content":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u714e\u9c7c\u3002<\/p>\n<p>\u4eca\u5929\u7ed9\u5927\u5bb6\u5206\u4eab\u7684\u4e00\u4e2a\u63d0\u6848\uff0c\u5df2\u7ecf\u5728 Go \u793e\u533a\u8ba8\u8bba\u4e86\u6574\u6574 9 \u5e74\uff082013~2022\uff09\uff0c\u5b83\u4e0e\u6211\u4eec\u7684\u65e5\u5e38\u7f16\u7a0b\u5bc6\u5207\u76f8\u5173\u3002<\/p>\n<p>\u4eca\u5929\u5c31\u7531\u714e\u9c7c\u548c\u5927\u5bb6\u4e00\u8d77\u6df1\u5165\u5b66\u4e60\u548c\u4e86\u89e3\u63d0\u6848\u300a<a href=\"https:\/\/link.segmentfault.com\/?enc=zFoI1QJV%2FeCooRtg%2F%2B%2FYUw%3D%3D.yFrbOUAR0nXScqMpC1Q9zfReM2GQtN5mcsF5DTyUSWIqG%2FOlFOTuLnjUZXhEapiq\" rel=\"nofollow\" title=\"proposal: spec: allow constants of arbitrary data structure type\">proposal: spec: allow constants of arbitrary data structure type<\/a>\u300b\u5427\uff0c\u770b\u770b\u6709\u6ca1\u6709\u4ec0\u4e48\u65b0\u7684\u60f3\u6cd5\u3002<\/p>\n<h2>\u80cc\u666f<\/h2>\n<p>\u6211\u4eec\u5148\u770b\u770b\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"go\">package main\n\nimport &quot;fmt&quot;\n\nfunc main() {\n    var each1 = []byte{'e', 'd', 'd', 'y'}\n    const each2 = []byte{'e', 'd', 'd', 'y'}\n    fmt.Printf(&quot;each1 is %q\/n&quot;, each1)\n    fmt.Printf(&quot;each2 is %q\/n&quot;, each2)\n}<\/code><\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c\u662f\u4ec0\u4e48\uff0c\u662f\u6b63\u5e38\u8f93\u51fa\u5417\uff0c\u8fd8\u662f\uff1f<\/p>\n<p>\u6700\u7ec8\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"shell\">.\/prog.go:7:16: []byte{\u2026} (value of type []byte) is not constant<\/code><\/pre>\n<p>\u7ed3\u679c\u662f Go \u7f16\u8bd1\u5931\u8d25\uff0c\u7f16\u8bd1\u65e0\u6cd5\u901a\u8fc7\u3002<\/p>\n<p>\u539f\u56e0\u662f\u7b2c 7 \u884c\uff08\u4e5f\u5c31\u662f const \u5173\u952e\u5b57\u90a3\u884c\uff09\u7684\u5e38\u91cf\u5b9a\u4e49\u6709\u9519\u8bef\uff0c\u7c7b\u578b\u4e3a <code>[]byte<\/code> \u7684\u503c\u662f\u4e0d\u80fd\u4f5c\u4e3a\u5e38\u91cf\u6765\u58f0\u660e\u5b9a\u4e49\u7684\u3002<\/p>\n<p>\u609f\u4e86\u4e5f\u96fe\u4e86\uff0cGo \u7684\u5e38\u91cf\u5b9a\u4e49\u6709\u7c7b\u578b\u9650\u5236\uff0c\u4e3a\u4ec0\u4e48\uff1f<\/p>\n<h2>\u671f\u671b<\/h2>\n<p>\u6211\u4eec\u7ed3\u5408\u53e6\u5916\u4e2a\u63d0\u6848\u300a<a href=\"https:\/\/link.segmentfault.com\/?enc=10ubj3n6%2F1VoGGd78WjgHQ%3D%3D.W4FkrYg3Xqvu7nGSF%2F4xJoplSwpIZyeNLdB1w7zXsVUoBTFJLM2Fc%2BRcN%2FgBS144\" rel=\"nofollow\" title=\"proposal: Go 2: add const literals for reference types like structs, maps, and arrays\">proposal: Go 2: add const literals for reference types like structs, maps, and arrays<\/a>\u300b\u6765\u770b\uff0c\u6307\u5411\u7684\u90fd\u662f\u540c\u7c7b\u8bc9\u6c42\u3002<\/p>\n<p>\u76ee\u7684\u662f\u80fd\u58f0\u660e\u7c7b\u4f3c\uff1a<\/p>\n<pre><code class=\"go\">const keys = [...]string{&quot;\u714e\u9c7c&quot;, &quot;eddycjy&quot;, ... }<\/code><\/pre>\n<p>\u671f\u5f85 Go \u80fd\u591f\u5141\u8bb8\u5b9a\u4e49\u5176\u4ed6\u7c7b\u578b\u7684\u5e38\u91cf\uff0c\u4f8b\u5982\uff1a\u7ed3\u6784\u4f53\uff08struct\uff09\u3001\u5b57\u5178\uff08map\uff09\u548c\u6570\u7ec4\uff08array\uff09\u7b49\uff0c\u4e0d\u4f1a\u518d\u4ea7\u751f\u7f16\u8bd1\u9519\u8bef\uff0c\u987a\u5229\u8fd0\u884c\u3002<\/p>\n<p>\u63a5\u53d7\u63d0\u6848\u540e\uff0c\u63d0\u6848\u4f5c\u8005\u8ba4\u4e3a\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u539f\u6709\u7684 Go \u4ee3\u7801\u6ca1\u6709\u5f71\u54cd\uff0c\u4e0d\u4f1a\u5b58\u5728\u7834\u574f\u6027\u5347\u7ea7\uff0c\u53ef\u4ee5\u6709\u6548\u7684\u7b80\u5316\u4ee3\u7801\u7b49\u3002<\/p>\n<p>\u4f60\u89c9\u5f97\u5462\uff0c\u8fd8\u6709\u6ca1\u6709\u522b\u7684\u66f4\u591a\u7684\u671f\u671b\uff1f<\/p>\n<h2>\u4e0d\u652f\u6301\u7684\u539f\u56e0<\/h2>\n<p>Go \u6838\u5fc3\u56e2\u961f\u7684 @Robert Griesemer \u8868\u793a\uff1a\u5e38\u91cf\u662f\u6545\u610f\u8bbe\u8ba1\u4e3a\u53ea\u652f\u6301\u57fa\u672c\u7c7b\u578b\u7684\uff08\u4ece Go \u7b2c\u4e00\u5929\u5f00\u59cb\u5c31\u88ab\u6784\u601d\u51fa\u6765\uff09\uff0c\u4e0d\u662f\u8bed\u8a00\u7684\u7f3a\u9677\uff0c\u4e5f\u4e0d\u662f\u8bbe\u8ba1\u7684\u7f3a\u9677\uff0c\u5e76\u8ba4\u4e3a\u5c06\u5176\u5f00\u653e\u7684\u5f71\u54cd\u6bd4\u60f3\u8c61\u4e2d\u6df1\u8fdc\u3002<\/p>\n<p>\u4e0d\u77e5\u9053\u8981\u5c06\u5e38\u91cf\u7684\u503c\u7c7b\u578b\u652f\u6301\u8981\u5f00\u653e\u5230\u4ec0\u4e48\u7a0b\u5ea6\uff0c\u652f\u6491\u5230 channel\u3001slice\u3001\u6307\u9488\u7c7b\u578b\uff1f\u6240\u4ee5\u5728\u4e0d\u786e\u5b9a\u6027\u4e0b\uff0c\u4e0d\u77e5\u9053\u590d\u6742\u5ea6\u6709\u591a\u5c11\uff0c\u5b98\u65b9\u8bd5\u56fe\u4fdd\u6301\u7c7b\u578b\u7cfb\u7edf\uff08\u5305\u62ec\u5e38\u91cf\u662f\u4ec0\u4e48\uff09\u7684\u76f8\u5bf9\u7b80\u5355\u3002<\/p>\n<p>\u4e0e\u6b64\u540c\u65f6\uff0c\u505a\u8fd9\u4ef6\u4e8b\u73b0\u9636\u6bb5\u8fd8\u770b\u4e0d\u5230\u660e\u663e\u7684\u6536\u76ca\u3002\u5982\u679c\u8981\u6539\uff0c\u4ec5\u6709\u53ef\u80fd\u5728 Go2 \u53d1\u751f\u4e00\u4e9b\u65b0\u7684\u8c03\u6574\uff0c\u800c\u4e0d\u662f Go1\u3002<\/p>\n<h2>\u771f\u5b9e\u573a\u666f<\/h2>\n<p>\u5728\u8bc4\u8bba\u533a\u4e2d\u770b\u5230\u6b27\u795e\uff08@Changkun Ou\uff09\u7559\u8a00\uff0c\u4e3e\u51fa\u4e86 \u201d\u5e38\u91cf\u9519\u8bef\u201c \u7684\u7ecf\u5178\u4f7f\u7528\u573a\u666f\u3002<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"go\">- const ErrVerification = errors.New(&quot;crypto\/rsa: verification error&quot;)\n+ var ErrVerification = errors.New(&quot;crypto\/rsa: verification error&quot;)<\/code><\/pre>\n<p>\u5982\u679c\u4ee5\u4e0b\u4ee3\u7801\u51fa\u73b0\u5728\u9879\u76ee\u4f9d\u8d56\u9879\u4e4b\u4e00\u4e2d\uff0c\u5219\u5b83\u4f1a\u7834\u574f\u6574\u4e2a\u7cfb\u7edf\uff1a<\/p>\n<pre><code class=\"go\">import &quot;cropto\/rsa&quot;\nfunc init() {\n    rsa.ErrVerification = nil\n}<\/code><\/pre>\n<p>\u8fd9\u662f\u5728\u9879\u76ee\u4ee3\u7801\u4e2d\u5f88\u5e38\u89c1\u7684\uff0c\u6700\u65e9\u5185\u90e8\u5305\u60f3\u5b9a\u4e49 const \u7684\u5e38\u91cf\u9519\u8bef\uff0c\u6700\u540e\u53ea\u80fd\u88ab\u8feb var \u6d41\u64cd\u4f5c\u4e00\u628a\u3002<\/p>\n<p>\u5728\u8fd9\u4e9b\u573a\u666f\u4e0b\uff0c\u4f60\u7684\u503c\u5728\u54ea\u91cc\u88ab\u4eba\u6539\u4e86\uff0c\u90fd\u4e0d\u786e\u5b9a\uff0c\u8fd8\u5f97\u67e5\u534a\u5929\uff0c\u6839\u672c\u539f\u56e0\u662f Go \u7684\u4e0d\u53ef\u53d8\u53d8\u91cf\u7684\u529f\u80fd\u90e8\u5206\u7f3a\u5931\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u5728\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86 Go \u4e2d\u6700\u5e38\u89c1\u7684\u5e38\u91cf\uff08const\uff09\uff0c\u5b9e\u9645\u4e0a\u5b83\u4ec5\u652f\u6301\u57fa\u672c\u7c7b\u578b\u7684\u5b9a\u4e49\u3002\u800c\u9488\u5bf9\u5b83\u7684\u4e0d\u8db3\u6211\u4eec\u7ed3\u5408\u4e86\u63d0\u6848\u4e2d\u7684\u8ba8\u8bba\u548c\u4f7f\u7528\u573a\u666f\u8fdb\u884c\u4e86\u8bf4\u660e\u3002<\/p>\n<p>\u76f8\u8f83\u800c\u8a00\uff0cGo \u5b98\u65b9\u5bf9\u6b64\u5e38\u91cf\u7684\u7c7b\u578b\u652f\u6301\u975e\u5e38\u8c28\u614e\uff0c\u8ba4\u4e3a\u6536\u76ca\u4e0d\u660e\u786e\u3001\u590d\u6742\u5ea6\u6709\u53ef\u80fd\u589e\u9ad8\uff0c\u8ba4\u4e3a\u7b80\u5355\u5c31\u597d\u4e86\u3002<\/p>\n<p>\u4f60\u53c8\u600e\u4e48\u770b\u5462\uff1f\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u7559\u8a00\u548c\u8ba8\u8bba\u3002<\/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=RZ%2FEGnuSDAX99GV8JsufWA%3D%3D.nsM1RUPeq2xEIwAmzolTShAm4J%2F%2Bgj5r0fnatwJnB5s%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=yy%2FRJqilSvr7z6ZbhQ4a9Q%3D%3D.vGrGYprY9Gicv%2BLVYmqw9DUD6%2FwIKx2wv6lJA99Lsdd2kMOiad%2FDa%2BJg8A6A%2Bwed\" 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=Z%2F0LzpzYcwDOblOKgt%2FowA%3D%3D.fy073IIHPp1iCdjmy8sV9eRz2cJY9zpUS3VXMNgR%2FLMtpxZIdfV08w9GsylN9p0R\" 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=E2%2BLR%2BDFi8sG%2BYO%2BrLrZvQ%3D%3D.Gvj7XX0VHApqSJ0h%2BMZwWh99ClB1OuLdm9cR4kNGdOU%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=vJBs5B17UDDKLX%2BYXt7VOw%3D%3D.7kqrDAMLxSRtoiunuK5sTGHrvccjUPtZKoQywyYhKjw%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=1N5ksztCpQPt1E6LNeImxg%3D%3D.zZBI1SqSSOGVYuIH3xO2AlnTIThjK0%2BgR87FQoWPB78%3D\" rel=\"nofollow\">Go \u8bed\u8a00\u8fdb\u9636\u4e4b\u65c5\uff1a\u8fdb\u4e00\u6b65\u6df1\u5165 Go \u6e90\u7801<\/a><\/li>\n<\/ul>\n<h2>\u66f4\u591a\u9605\u8bfb<\/h2>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=CrnpPWhrbGsMF3Uv3bwoOg%3D%3D.TaA%2FzQ%2BsmqsyZ0B08UOkVw3ItFfx4lfHTN3oMH10IU%2Fq4LWac%2B1XXeKiJwZ1Y2QWKShgzz%2BFLP%2BF2CLLdBGA5g%3D%3D\" rel=\"nofollow\">Go \u60f3\u8981\u52a0\u4e2a\u7bad\u5934\u8bed\u6cd5\uff0c\u8fd9\u4e0b\u66f4\u50cf PHP \u4e86\uff01<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=es24tRg4%2Bqwqb869a6grww%3D%3D.%2B7mKqDcKDw8Q1wk7OI1Y4LfrlVbGHiIlDRMhBYOkwSnB%2FwAfoX1iqTSk2xN9GVuoQFOwYqqigWxRd1fdQoQ7bA%3D%3D\" rel=\"nofollow\">Go \u9519\u8bef\u5904\u7406\u65b0\u601d\u8def\uff1f\u7528\u5de6\u4fa7\u51fd\u6570\u548c\u8868\u8fbe\u5f0f<\/a><\/li>\n<\/ul>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042196335\">https:\/\/segmentfault.com\/a\/1190000042196335<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u714e\u9c7c\u3002 \u4eca\u5929\u7ed9\u5927\u5bb6\u5206\u4eab\u7684\u4e00\u4e2a\u63d0\u6848\uff0c\u5df2\u7ecf\u5728 Go \u793e\u533a\u8ba8\u8bba\u4e86\u6574\u6574 9 \u5e74\uff082013~2022\uff09\uff0c\u5b83\u4e0e [&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-10005990","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\/10005990","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=10005990"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10005990\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10005990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10005990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10005990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}