{"id":220,"date":"2024-06-13T17:49:08","date_gmt":"2024-06-13T09:49:08","guid":{"rendered":"http:\/\/www.shifengzhi.asia\/?p=220"},"modified":"2024-06-15T21:17:36","modified_gmt":"2024-06-15T13:17:36","slug":"go%e5%9f%ba%e7%a1%80%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/boki.shifengzhi.top\/?p=220","title":{"rendered":"GO\u57fa\u7840\u5165\u95e8"},"content":{"rendered":"<h2>Go\u7b80\u4ecb<\/h2>\n<p>Go\u8bed\u8a00\uff0cGo \u8bed\u8a00\u8d77\u6e90 2007 \u5e74\uff0c\u5e76\u4e8e 2009 \u5e74\u6b63\u5f0f\u5bf9\u5916\u53d1\u5e03\uff0c\u53c8\u79f0\u4e3aGolang\uff0c\u662f\u7531Google\u4e09\u4f4d\u9876\u5c16\u5927\u795e\u5f00\u53d1\u7684\u4e00\u79cd\u9759\u6001\u7c7b\u578b\u3001\u7f16\u8bd1\u578b\u8bed\u8a00\u3002\u5b83\u65e8\u5728\u63d0\u9ad8\u591a\u6838\u5904\u7406\u5668\u7684\u7f16\u7a0b\u6548\u7387\uff0c\u5e76\u4e14\u4f7f\u5f97\u7f16\u7a0b\u66f4\u52a0\u7b80\u5355\u548c\u9ad8\u6548\u3002Go\u8bed\u8a00\u5177\u6709\u4ee5\u4e0b\u7279\u70b9\uff1a<\/p>\n<ol>\n<li><strong>\u7b80\u6d01\u6027<\/strong>\uff1aGo\u8bed\u8a00\u7684\u8bed\u6cd5\u7b80\u5355\uff0c\u6613\u4e8e\u5b66\u4e60\uff0c\u5e76\u4e14\u5bb9\u6613\u7f16\u5199\u3002<\/li>\n<li><strong>\u9ad8\u6027\u80fd<\/strong>\uff1aGo\u8bed\u8a00\u662f\u7f16\u8bd1\u578b\u8bed\u8a00\uff0c\u7f16\u8bd1\u540e\u7684\u7a0b\u5e8f\u8fd0\u884c\u901f\u5ea6\u5feb\u3002<\/li>\n<li><strong>\u5e76\u53d1\u6027<\/strong>\uff1aGo\u8bed\u8a00\u5185\u7f6e\u4e86\u5e76\u53d1\u7f16\u7a0b\u7684\u652f\u6301\uff0c\u901a\u8fc7goroutine\u548cchannel\u7b80\u5316\u4e86\u5e76\u53d1\u7f16\u7a0b\u3002<\/li>\n<li><strong>\u5783\u573e\u56de\u6536<\/strong>\uff1aGo\u8bed\u8a00\u62e5\u6709\u81ea\u52a8\u5783\u573e\u56de\u6536\u673a\u5236\uff0c\u51cf\u8f7b\u4e86\u7a0b\u5e8f\u5458\u7684\u8d1f\u62c5\u3002<\/li>\n<li><strong>\u5185\u5b58\u5b89\u5168<\/strong>\uff1aGo\u8bed\u8a00\u5728\u7f16\u8bd1\u671f\u95f4\u8fdb\u884c\u591a\u79cd\u68c0\u67e5\uff0c\u786e\u4fdd\u5185\u5b58\u5b89\u5168\u3002<\/li>\n<li><strong>\u4e30\u5bcc\u7684\u6807\u51c6\u5e93<\/strong>\uff1aGo\u8bed\u8a00\u62e5\u6709\u4e30\u5bcc\u7684\u6807\u51c6\u5e93\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u5b9e\u7528\u7684\u529f\u80fd\u3002<\/li>\n<li><strong>\u8de8\u5e73\u53f0<\/strong>\uff1aGo\u8bed\u8a00\u652f\u6301\u8de8\u5e73\u53f0\u7f16\u8bd1\uff0c\u53ef\u4ee5\u5728\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u3002<\/li>\n<li><strong>\u5de5\u5177\u94fe<\/strong>\uff1aGo\u8bed\u8a00\u62e5\u6709\u5f3a\u5927\u7684\u5de5\u5177\u94fe\uff0c\u5305\u62ecgofmt\uff08\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177\uff09\u3001go test\uff08\u6d4b\u8bd5\u5de5\u5177\uff09\u7b49\u3002<\/li>\n<\/ol>\n<p>Go\u8bed\u8a00\u9002\u7528\u4e8e\u591a\u79cd\u573a\u666f\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a<\/p>\n<ul>\n<li>\u7f51\u7edc\u7f16\u7a0b\u548c\u670d\u52a1\u5668\u7aef\u5e94\u7528<\/li>\n<li>\u5206\u5e03\u5f0f\u7cfb\u7edf<\/li>\n<li>\u5fae\u670d\u52a1\u67b6\u6784<\/li>\n<li>\u4e91\u8ba1\u7b97<\/li>\n<li>DevOps\u5de5\u5177\u548c\u81ea\u52a8\u5316\u811a\u672c<\/li>\n<\/ul>\n<p>Go\u8bed\u8a00\u7684\u8fd9\u4e9b\u7279\u6027\u4f7f\u5176\u6210\u4e3a\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u4e2d\u975e\u5e38\u53d7\u6b22\u8fce\u7684\u9009\u62e9\u4e4b\u4e00\u3002<\/p>\n<p>\u6ce8\uff1a\u56e0\u4e3ago\u5b98\u7f51golang.org\u5728\u56fd\u5185\u6253\u4e0d\u5f00\uff0c\u53ef\u4ee5\u4f7f\u7528<code>godoc -http=:8080<\/code>\u5728\u81ea\u5df1\u672c\u5730\u76848080\u7aef\u53e3\u5f00\u4e00\u4e2a\u4e00\u6837\u7684\u5b98\u65b9\u8fdb\u884c\u6d4f\u89c8<\/p>\n<h2>Go\u7684\u57fa\u7840\u7ed3\u6784\u4e0e\u57fa\u672c\u6570\u636e\u7c7b\u578b<\/h2>\n<h3>\u6587\u4ef6\u540d\u3001\u5173\u952e\u5b57\u4e0e\u6807\u8bc6\u7b26<\/h3>\n<p>\u5982\u679cGo\u6587\u4ef6\u7684\u6587\u4ef6\u540d\u7531\u591a\u4e2a\u90e8\u5206\u7ec4\u6210\uff0c\u5219\u4f7f\u7528\u4e0b\u5212\u7ebf <code>_<\/code> \u5bf9\u5b83\u4eec\u8fdb\u884c\u5206\u9694\uff0c\u5982 <code>scanner_test.go<\/code> \u3002\u6587\u4ef6\u540d\u4e0d\u5305\u542b\u7a7a\u683c\u6216\u5176\u4ed6\u7279\u6b8a\u5b57\u7b26\u3002<\/p>\n<p>\u6ce8\u610f\uff1a<code>_<\/code> \u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u6807\u8bc6\u7b26\uff0c\u88ab\u79f0\u4e3a\u7a7a\u767d\u6807\u8bc6\u7b26\u3002\u5b83\u53ef\u4ee5\u50cf\u5176\u4ed6\u6807\u8bc6\u7b26\u90a3\u6837\u7528\u4e8e\u53d8\u91cf\u7684\u58f0\u660e\u6216\u8d4b\u503c\uff08\u4efb\u4f55\u7c7b\u578b\u90fd\u53ef\u4ee5\u8d4b\u503c\u7ed9\u5b83\uff09\uff0c\u4f46\u4efb\u4f55\u8d4b\u7ed9\u8fd9\u4e2a\u6807\u8bc6\u7b26\u7684\u503c\u90fd\u5c06\u88ab\u629b\u5f03\uff0c\u56e0\u6b64\u8fd9\u4e9b\u503c\u4e0d\u80fd\u5728\u540e\u7eed\u7684\u4ee3\u7801\u4e2d\u4f7f\u7528\uff0c\u4e5f\u4e0d\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u6807\u8bc6\u7b26\u4f5c\u4e3a\u53d8\u91cf\u5bf9\u5176\u5b83\u53d8\u91cf\u8fdb\u884c\u8d4b\u503c\u6216\u8fd0\u7b97\u3002<\/p>\n<p>\u5728\u7f16\u7801\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u6ca1\u6709\u540d\u79f0\u7684\u53d8\u91cf\u3001\u7c7b\u578b\u6216\u65b9\u6cd5\u3002\u867d\u7136\u8fd9\u4e0d\u662f\u5fc5\u987b\u7684\uff0c\u4f46\u6709\u65f6\u5019\u8fd9\u6837\u505a\u53ef\u4ee5\u6781\u5927\u5730\u589e\u5f3a\u4ee3\u7801\u7684\u7075\u6d3b\u6027\uff0c\u8fd9\u4e9b\u53d8\u91cf\u88ab\u7edf\u79f0\u4e3a\u533f\u540d\u53d8\u91cf\u3002<\/p>\n<h3>Go \u4ee3\u7801\u4e2d\u4f1a\u4f7f\u7528\u5230\u7684 25 \u4e2a\u5173\u952e\u5b57\u6216\u4fdd\u7559\u5b57<\/h3>\n<table>\n<thead>\n<tr>\n<th>break<\/th>\n<th>default<\/th>\n<th>func<\/th>\n<th>interface<\/th>\n<th>select<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>case<\/td>\n<td>defer<\/td>\n<td>go<\/td>\n<td>map<\/td>\n<td>struct<\/td>\n<\/tr>\n<tr>\n<td>chan<\/td>\n<td>else<\/td>\n<td>goto<\/td>\n<td>package<\/td>\n<td>switch<\/td>\n<\/tr>\n<tr>\n<td>const<\/td>\n<td>fallthrough<\/td>\n<td>if<\/td>\n<td>range<\/td>\n<td>type<\/td>\n<\/tr>\n<tr>\n<td>continue<\/td>\n<td>for<\/td>\n<td>import<\/td>\n<td>return<\/td>\n<td>var<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Go \u8bed\u8a00\u8fd8\u6709 36 \u4e2a\u9884\u5b9a\u4e49\u6807\u8bc6\u7b26<\/h3>\n<p><strong>\u5176\u4e2d\u5305\u542b\u4e86\u57fa\u672c\u7c7b\u578b\u7684\u540d\u79f0\u548c\u4e00\u4e9b\u57fa\u672c\u7684\u5185\u7f6e\u51fd\u6570<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>append<\/th>\n<th>bool<\/th>\n<th>byte<\/th>\n<th>cap<\/th>\n<th>close<\/th>\n<th>complex<\/th>\n<th>complex64<\/th>\n<th>complex128<\/th>\n<th>uint16<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>copy<\/td>\n<td>false<\/td>\n<td>float32<\/td>\n<td>float64<\/td>\n<td>imag<\/td>\n<td>int<\/td>\n<td>int8<\/td>\n<td>int16<\/td>\n<td>uint32<\/td>\n<\/tr>\n<tr>\n<td>int32<\/td>\n<td>int64<\/td>\n<td>iota<\/td>\n<td>len<\/td>\n<td>make<\/td>\n<td>new<\/td>\n<td>nil<\/td>\n<td>panic<\/td>\n<td>uint64<\/td>\n<\/tr>\n<tr>\n<td>print<\/td>\n<td>println<\/td>\n<td>real<\/td>\n<td>recover<\/td>\n<td>string<\/td>\n<td>true<\/td>\n<td>uint<\/td>\n<td>uint8<\/td>\n<td>uintptr<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u5b66\u4e60\u7b14\u8bb0<\/h2>\n<p><strong>\u56e0\u4e3ago\u5b98\u7f51golang.org\u5728\u56fd\u5185\u6253\u4e0d\u5f00\uff0c\u53ef\u4ee5\u4f7f\u7528<code>godoc -http=:8080<\/code>\u5728\u81ea\u5df1\u672c\u5730\u76848080\u7aef\u53e3\u5f00\u4e00\u4e2a\u4e00\u6837\u7684\u5b98\u65b9\u8fdb\u884c\u6d4f\u89c8<\/strong><\/p>\n<h3>\u9879\u76ee\u7ed3\u6784<\/h3>\n<p>\u6839\u636eGo\u7ea6\u5b9a\uff0cgopath\u76ee\u5f55\u4e0b\u5e94\u5305\u542b\u4e09\u4e2a\u6587\u4ef6\u5939\uff1a<\/p>\n<ul>\n<li>bin\uff1a\u5b58\u653e\u7f16\u8bd1\u540e\u7684\u53ef\u6267\u884c\u6587\u4ef6<\/li>\n<li>pkg\uff1a\u5b58\u653e\u7f16\u8bd1\u540e\u751f\u6210\u7684\u5305\u6587\u4ef6\uff0c\u4e00\u822c\u662f\u4ee5<code>.a<\/code>\u4e3a\u540e\u7f00\u7684\u6587\u4ef6<\/li>\n<li>src\uff1a\u5b58\u653e\u9879\u76ee\u7684\u6e90\u7801<\/li>\n<\/ul>\n<h3>\u5305\u522b\u540d<\/h3>\n<p>\u5728\u5bfc\u5165\u5305\u65f6\u53ef\u4ee5\u4e3a\u5176\u53d6\u522b\u540d\uff0c\u4f8b\u5982\u7ed9\u201dfmt\u201c\u53d6\u522b\u540d\u4e3astd\uff1a<code>import std &quot;fmt&quot;<\/code>\uff0c\u6b64\u5916\u6709\u4e00\u4e2a\u7279\u522b\u7528\u6cd5\uff0c\u5c31\u662f\u522b\u540d\u53d6\u4e3a<code>.<\/code>\uff0c\u8fd9\u6837\u5728\u8c03\u7528\u8be5\u5305\u51fd\u6570\u65f6\u524d\u9762\u65e0\u9700\u5199\u5305\u540d\uff0c\u88ab\u79f0\u4e3a\u7701\u7565\u8c03\u7528\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-go\">import . &quot;fmt&quot;\nfunc main(){\n    \/\/ \u7701\u7565fmt\u5305\u540d\u8c03\u7528\n    Println(&quot;Hello World!&quot;)\n}<\/code><\/pre>\n<p>\u5f53\u7136\uff0c\u7701\u7565\u8c03\u7528\u4e0d\u80fd\u548c\u522b\u540d\u540c\u65f6\u4f7f\u7528\uff0c\u4e0d\u7136\u522b\u540d\u5c31\u6ca1\u6709\u610f\u4e49\u4e86<\/p>\n<h3>\u8bbf\u95ee\u6743\u9650<\/h3>\n<p>\u5728Golang\u4e2d\u6839\u636e\u7ea6\u5b9a\u51fd\u6570\u540d<strong>\u9996\u5b57\u6bcd\u5c0f\u5199<\/strong>\u5373\u4e3a<code>private<\/code>\uff0c\u51fd\u6570\u540d<strong>\u9996\u5b57\u6bcd\u5927\u5199<\/strong>\u5373\u4e3a<code>public<\/code><\/p>\n<h3>go\u57fa\u672c\u7c7b\u578b<\/h3>\n<ul>\n<li>bool\uff1a\u5e03\u5c14\u578b\uff0c1\u5b57\u8282\uff0c\u53ea\u6709true\u548cfalse\uff0c\u4e0d\u80fd\u7528\u6570\u5b57\u4ee3\u8868<\/li>\n<li>int\/uint\uff1a\u6574\u578b\uff0c\u6839\u636e\u8fd0\u884c\u5e73\u53f0\u53ef\u80fd\u4e3a32\u621664\u4f4d\n<ul>\n<li>int8\/uint8\uff1a8\u4f4d\u6574\u578b\uff0c1\u5b57\u8282<\/li>\n<\/ul>\n<\/li>\n<li>byte\uff1a\u5b57\u8282\u578b\uff08uint8\u7684\u522b\u540d\uff0c\u65e0\u7b26\u53f78\u4f4d\u6574\u578b\uff09<\/li>\n<li>rune\uff1aint32\u7684\u522b\u540d<\/li>\n<li>float\/float64\uff1a4\/8\u5b57\u8282\uff0c\u7cbe\u786e\u5230\u5c0f\u6570\u70b9\u540e7\/15\u4f4d<\/li>\n<li>\u590d\u6570\uff1acomplex64\/complex128\uff0c\u957f\u5ea6\uff1a8\/16\u5b57\u8282<\/li>\n<li>\u8db3\u591f\u4fdd\u5b58\u6307\u9488\u768432\u4f4d\u621664\u4f4d\u6574\u578b\uff1auintptr<\/li>\n<li>\u5176\u4ed6\u503c\u7c7b\u578b\uff1aarray\uff0cstruct\uff0cstring<\/li>\n<li>\u5f15\u7528\u7c7b\u578b\uff1aslice\uff08\u5207\u7247\uff09\uff0cmap\uff0cchan\uff08\u901a\u9053\uff09<\/li>\n<li>\u63a5\u53e3\u7c7b\u578b\uff1ainterface<\/li>\n<li>\u51fd\u6570\u7c7b\u578b\uff1afunc<\/li>\n<\/ul>\n<h3>\u53d8\u91cf\u58f0\u660e<\/h3>\n<pre><code class=\"language-go\">\/\/ \u5168\u5c40\u53d8\u91cf\nvar a int = 1\nvar b int\nvar c = 1\nd := 1\nvar (e = 1, f = 2)\n\/\/ \u5c40\u90e8\u53d8\u91cf\nfunc main(){\n    var a,b,c,d = 1,2,3,4\n    x,y,z := 1,2,3\n}<\/code><\/pre>\n<pre><code class=\"language-go\">var a int = 1\nb := string(a)\nfmt.Println(b) \/\/ \u8f93\u51faA\n\/\/ \u5982\u679c\u60f3\u8981\u8f93\u51fa\u5b57\u7b26\u4e32\u768465\uff0c\u9700\u8981\u4f7f\u7528\u5305\u201cstrconv\u201d\nb := strconv.Itoa(a)\nfmt.Println(b) \/\/ \u8f93\u51fa\u5b57\u7b26\u4e3265\nc := strconv.AtoI(b) \/\/ \u4ece\u5b57\u7b26\u4e32\u8f6c\u56de\u6570\u5b57<\/code><\/pre>\n<h3>\u5e38\u91cf<\/h3>\n<p>\u4e00\u822c\u89c4\u8303\u4e2d\u5b9a\u4e49\u5e38\u91cf\u4f7f\u7528\u5168\u90e8\u5927\u5199\u5b57\u6bcd\u6765\u5b9a\u4e49\uff0c\u4f46\u662f\u7531\u4e8egolang\u89c4\u5219\u4e2d\u9996\u5b57\u6bcd\u5927\u5199\u8868\u793a\u53ef\u4ee5\u88ab\u5916\u90e8\u5305\u8c03\u7528\uff0c\u5982\u679c\u60f3\u58f0\u660e\u79c1\u6709\u5e38\u91cf\u4e00\u822c\u4f1a\u7528<code>_<\/code>\u6216\u5c0f\u5199\u5b57\u6bcd<code>c<\/code>\u5f00\u5934\uff0c\u5982\uff1a<\/p>\n<pre><code class=\"language-go\">const _MAX = 10\nconst cNAME = &quot;JOJO&quot;<\/code><\/pre>\n<p>\u5e38\u91cf\u7684\u53f3\u4fa7\u53ea\u80fd\u662f\u5e38\u91cf\u6216\u5e38\u91cf\u8868\u8fbe\u5f0f\uff0c\u4f7f\u7528\u51fd\u6570\u4e5f\u53ea\u80fd\u662f\u5185\u7f6e\u7684\u51fd\u6570\uff0c\u5982\u679c\u4e0d\u8d4b\u503c\u5c06\u4f7f\u7528\u4e0a\u4e00\u884c\u7684\u503c<\/p>\n<pre><code class=\"language-go\">const (\n    A = &quot;123&quot;\n    B = len(a)\n    C\n    D\n)<\/code><\/pre>\n<p>\u56e0\u6b64\u4e0a\u8ff0\u4ee3\u7801\u4e2da\u4e3a\u201c123\u201d\uff0cb\u4e3a3\uff0cc\u548cd\u4e5f\u90fd\u4e3a3<\/p>\n<p>\u6ce8\u610f\uff1a\u4f7f\u7528\u4e0a\u4e00\u884c\u7684\u503c\u65f6\u8981\u4fdd\u8bc1\u6bcf\u884c\u58f0\u660e\u7684\u5e38\u91cf\u4e2a\u6570\u8981\u4e00\u6837<\/p>\n<pre><code class=\"language-go\">const (\n    A, B = 1, 2\n    C \/\/ \u8fd9\u662f\u4e0d\u884c\u7684\uff0c\u4e0e\u4e0a\u4e00\u884c\u4e2a\u6570\u4e0d\u4e00\u81f4\n    C, D \/\/ \u8fd9\u4e2a\u53ef\u4ee5\uff0cc\u4e3a1\uff0cd\u4e3a2\n)<\/code><\/pre>\n<p>\u5728Golang\u4e2d\uff0c\u6709<code>iota<\/code>\u4f5c\u4e3a\u5e38\u91cf\u7684\u8ba1\u6570\u5668\uff0c\u521d\u59cb\u4e3a0\uff0c\u6bcf\u5b9a\u4e49\u4e00\u4e2a\u5e38\u91cfiota\u5c31\u4f1a\u589e\u52a01\uff0c\u540c\u65f6\u6bcf\u9047\u5230<code>const<\/code>\u65f6<code>iota<\/code>\u90fd\u4f1a\u53d8\u4e3a0\uff0c\u56e0\u6b64\u679a\u4e3e\u5e94\u5199\u5728\u4e00\u4e2a\u5e38\u91cf\u7ec4\u4e2d<\/p>\n<h3>\u8fd0\u7b97\u7b26<\/h3>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/tuchuang.shifengzhi.asia\/picture\/go.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/tuchuang.shifengzhi.asia\/picture\/go.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240602102145861\" \/><\/div><\/p>\n<p><strong><code>&lt;&lt;<\/code><\/strong>\u8fd0\u7b97\u7b26\u5c06\u4e00\u4e2a\u6570\u5de6\u79fb n \u4f4d\uff0c\u76f8\u5f53\u4e8e\u5c06\u8be5\u6570<strong>\u4e58<\/strong>\u4ee5$2^n$\uff1b<strong><code>&gt;&gt;<\/code><\/strong>\u8fd0\u7b97\u7b26\u5c06\u4e00\u4e2a\u6570\u53f3\u79fb n \u4f4d\uff0c\u76f8\u5f53\u4e8e\u5c06\u8be5\u6570<strong>\u9664<\/strong>\u4ee5$2^n$\u3002<\/p>\n<p>\u5728golang\u4e2d\uff0c<code>++<\/code>\u548c<code>--<\/code>\u662f\u4f5c\u4e3a\u8bed\u53e5\u5b58\u5728\uff0c\u800c\u4e0d\u50cf\u5176\u4ed6\u8bed\u8a00\u4e2d\u4f5c\u4e3a\u8868\u8fbe\u5f0f\uff0c\u56e0\u6b64\u4e0d\u80fd\u653e\u5728\u7b49\u53f7\u53f3\u4fa7\uff0c\u53ea\u80fd\u4f5c\u4e3a\u5355\u72ec\u7684\u4e00\u884c<\/p>\n<h3>\u63a7\u5236\u8bed\u53e5<\/h3>\n<h4>\u5206\u652f<\/h4>\n<p>golang\u4e2d\u7684 if \u540e\u9762\u6ca1\u6709\u5c0f\u62ec\u53f7\uff08\uff09\uff0c\u76f4\u63a5\u7528\u7a7a\u683c\u5206\u9694if\u5173\u952e\u5b57\u4e0e\u6761\u4ef6\uff0c\u7c7b\u4f3cpython\uff0c\u4f46\u662f\u540e\u9762\u4f9d\u65e7\u662f\u5728\u540c\u4e00\u884c\u63a5\u5de6\u5927\u62ec\u53f7\uff0c\u5de6\u5927\u62ec\u53f7\u4e0d\u80fd\u6362\u884c\uff0c\u5426\u5219\u7f16\u8bd1\u9519\u8bef\u3002\u5e76\u4e14\u53ef\u4ee5\u5728\u5199\u6761\u4ef6\u7684\u90e8\u5206\u58f0\u660e\u65b0\u53d8\u91cf\uff0c\u6b64\u53d8\u91cf\u4e3a\u5c40\u90e8\u53d8\u91cf\uff0c\u5982\u679c\u4e0e\u5916\u90e8\u53d8\u91cf\u540c\u540d\u5219\u4f1a\u9690\u85cf\u5916\u90e8\u53d8\u91cf\uff0c\u4f7f\u7528\u5b9a\u4e49\u7684\u5c40\u90e8\u53d8\u91cf\uff0c\u5b9a\u4e49\u53d8\u91cf\u4e0e\u540e\u9762\u6761\u4ef6\u7528\u5206\u53f7<code>;<\/code>\u5206\u9694<\/p>\n<p>switch\uff1agolang\u4e2d\u7684switch\u4e0d\u9700\u8981\u6bcf\u4e2acase\u90fd\u5199break\uff0c\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684case\u540e\u4f1a\u81ea\u52a8break\u8df3\u51fa\u6574\u4e2aswitch\uff0c\u5982\u679c\u4f60\u60f3\u8981\u5b83\u7ee7\u7eed\u5411\u4e0b\u9a8c\u8bc1\u53ef\u4ee5\u4f7f\u7528<code>fallthrough<\/code>\u663e\u5f0f\u58f0\u660e\uff0c\u5e76\u4e14golang\u4e2d\u7684switch\u4e5f\u6709\u4e0d\u540c\u5f62\u5f0f<\/p>\n<pre><code class=\"language-go\">\/\/ \u7b2c\u4e00\u79cd\na := 1\nswitch a {\n    case 0:\n        fmt.Println(&quot;a=0&quot;)\n    case 1:\n        fmt.Println(&quot;a=1&quot;) \/\/ \u53ea\u4f1a\u8f93\u51faa=1\n    default:\n        fmt.Println(&quot;None&quot;)\n}\n\/\/ \u7b2c\u4e8c\u79cd\na := 1\nswitch {\n    case a &gt;= 0:\n        fmt.Println(&quot;a&gt;=0&quot;) \/\/ \u53ea\u4f1a\u8f93\u51faa&gt;=0\n    case a &gt;= 1:\n        fmt.Println(&quot;a&gt;=1&quot;)\n    default:\n        fmt.Println(&quot;None&quot;)\n}\n\/\/ \u4f7f\u7528 fallthrough\na := 1\nswitch {\n    case a &gt;= 0:\n        fmt.Println(&quot;a&gt;=0&quot;) \/\/ \u4f1a\u8f93\u51faa&gt;=0\n        fallthrough\n    case a &gt;= 1:\n        fmt.Println(&quot;a&gt;=1&quot;) \/\/ \u4e5f\u4f1a\u8f93\u51faa&gt;=0\n    default:\n        fmt.Println(&quot;None&quot;)\n}\n\/\/ \u5c40\u90e8\u53d8\u91cfa\nswitch a := 1; {\n    case a &gt;= 0:\n        fmt.Println(&quot;a&gt;=0&quot;) \/\/ \u4f1a\u8f93\u51faa&gt;=0\n        fallthrough\n    case a &gt;= 1:\n        fmt.Println(&quot;a&gt;=1&quot;) \/\/ \u4e5f\u4f1a\u8f93\u51faa&gt;=0\n    default:\n        fmt.Println(&quot;None&quot;)\n}<\/code><\/pre>\n<h4>\u5faa\u73af<\/h4>\n<p>golang\u4e2d\u7684\u5faa\u73af\u53ea\u6709<code>for<\/code>\u4e00\u79cd\uff0c\u4f46\u662f\u8fd9\u91cc\u7684for\u66f4\u591a\u6837\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-go\">\/\/ \u7b2c\u4e00\u79cd\nfor {\n    a++\n    if a &gt; 3 {\n        break\n    }\n}\n\/\/ \u7b2c\u4e8c\u79cd\nfor a &lt; 3 {\n    a++\n}\n\/\/ \u7b2c\u4e09\u79cd\nfor a := 0; a &lt; 3; a++ {\n    fmt.println(a)\n}<\/code><\/pre>\n<h3>break,continue,goto<\/h3>\n<p>go\u4e2d\u7684break\u548ccontinue\u9664\u4e86\u5728\u5176\u4ed6\u8bed\u8a00\u4e2d\u7684\u7528\u6cd5\u5916\u8fd8\u53ef\u4ee5\u914d\u5408\u6807\u7b7e\u4f7f\u7528<\/p>\n<pre><code class=\"language-go\">LABLE:\n    for {\n        for i := 0; i &lt; 3; i++ {\n            if i &gt; 1 {\n                break LABLE \/\/ \u76f4\u63a5\u8df3\u51faLABLE\u5904\u7684\u5faa\u73af\n            }\n        }\n    }\n\/\/ go to\nfor {\n    for i := 0; i &lt; 3; i++ {\n        if i &gt; 1 {\n            goto LABLE \/\/ \u76f4\u63a5\u8df3\u5230LABLE\u5904\u5f00\u59cb\u6267\u884c\n        }\n    }\n}\nLABLE:\n    fmt.Println(&quot;goto \u5230\u6b64\u5904&quot;)<\/code><\/pre>\n<p>continue\u4e5f\u662f\u540c\u7406\uff0c\u5e26\u4e0a\u6807\u7b7e\u5c31\u662f\u8df3\u8fc7\u6807\u7b7e\u5904\u7684\u5f53\u524d\u8fd9\u6b21\u5faa\u73af<\/p>\n<h3>\u6570\u7ec4<\/h3>\n<p>go\u4e2d\u7684\u6570\u7ec4\u4e3a\u503c\u7c7b\u578b\uff0c\u5728\u4f7f\u7528\u65f6\u662f\u5bf9\u6570\u7ec4\u8fdb\u884c\u62f7\u8d1d\uff0c\u5e76\u4e0d\u662f\u50cf\u5176\u4ed6\u8bed\u8a00\u90a3\u6837\u662f\u5f15\u7528\u7c7b\u578b\u6307\u5411\u540c\u4e00\u4e2a\u5730\u5740<\/p>\n<p>\u6570\u7ec4\u4e4b\u95f4\u53ef\u4ee5\u4f7f\u7528<code>==<\/code>\u548c<code>!=<\/code>\u8fdb\u884c\u6bd4\u8f83\uff0c\u4f46\u662f\u4e0d\u80fd\u4f7f\u7528<code>&lt;<\/code>\u548c<code>&gt;<\/code>\uff0c\u5e76\u4e14\u7c7b\u578b\u4e0d\u540c\u4e5f\u662f\u4e0d\u80fd\u8fdb\u884c\u6bd4\u8f83<\/p>\n<pre><code class=\"language-go\">var a [2]int \/\/ \u7c7b\u578b\u4e3a \u957f\u5ea6\u4e3a2\u7684\u6574\u578b\nvar a [1]int \/\/ \u7c7b\u578b\u4e3a \u957f\u5ea6\u4e3a1\u7684\u6574\u578b\uff0c\u4e24\u4e2a\u6570\u7ec4\u7c7b\u578b\u4e0d\u540c\n\/\/ \u524d19\u4e2a\u5143\u7d20\u4e3a0\uff0c\u7b2c20\u4e2a\u5143\u7d20\u4e3a1\na := [20]int{19: 1}\n\/\/ \u5df2\u77e5\u6570\u7ec4\u5185\u5bb9\u53ef\u4ee5\u7528 ... \u7701\u7565\u6570\u7ec4\u5143\u7d20\u4e2a\u6570\na := [...]int{1,2,3,4,5}\na := [...]int{19: 1} \/\/ \u8fd9\u6837\u4e5f\u662f\u53ef\u4ee5\u7684\uff0c\u548c\u4e0a\u9762\u7684\u6548\u679c\u4e00\u6837<\/code><\/pre>\n<p>\u6307\u5411\u6570\u7ec4\u7684\u6307\u9488\u548c\u6307\u9488\u6570\u7ec4<\/p>\n<pre><code class=\"language-go\">\/\/ \u6307\u5411\u6570\u7ec4\u7684\u6307\u9488\na := [...]int{3: 1}\nvar p *[4]int = &amp;a \/\/ p\u7684\u503c\u4e3a &amp;[0,0,0,1]\uff0c\u5c31\u662f\u6253\u5370a\u7684\u503c\u524d\u9762\u52a0\u4e0a\u4e86&amp;\uff0c\u8868\u793a\u53d6\u8fd9\u4e2a\u6570\u7ec4\u7684\u5730\u5740\n\/\/ new\np := new([5]int) \/\/ \u4f7f\u7528new\u8fd9\u79cd\u5f62\u5f0f\u5f97\u5230\u7684\u4f9d\u65e7\u662f\u6307\u9488\uff0cp\u7684\u503c\u4e3a &amp;[0,0,0,0,0]\n\/\/ \u6307\u9488\u6570\u7ec4\nx, y = 1, 2\na := [...]*int{&amp;x, &amp;y} \/\/ \u662f\u4e00\u4e2a\u6307\u9488\u7c7b\u578b\u7684\u6570\u7ec4\uff0c\u91cc\u9762\u5b58\u653e\u4e86x\u548cy\u7684\u5730\u5740<\/code><\/pre>\n<p>go\u4e2d\u4e5f\u662f\u4f9d\u7136\u6709\u591a\u7ef4\u6570\u7ec4\uff0c\u4e5f\u662f\u53ea\u80fd\u7701\u7565\u524d\u9762\u4e0d\u80fd\u7701\u7565\u540e\u9762<\/p>\n<pre><code class=\"language-go\">a := [...][3]{{1,1,1},{2,2,2}}<\/code><\/pre>\n<p>\u7528golang\u5b9e\u73b0\u4e00\u4e0b\u7ecf\u5178\u7684\u5192\u6ce1\u6392\u5e8f<\/p>\n<pre><code class=\"language-go\">\/\/ \u5192\u6ce1\u6392\u5e8f\na := [...]int{5, 2, 6, 3, 9}\nfmt.Println(&quot;\u6392\u5e8f\u524d\uff1a&quot;, a)\nnum := len(a) \/\/ \u63d0\u524d\u8ba1\u7b97\u957f\u5ea6\u514d\u5f97\u6bcf\u6b21\u5faa\u73af\u90fd\u8981\u91cd\u65b0\u8ba1\u7b97\u6d6a\u8d39\u8d44\u6e90\nfor i := 0; i &lt; num; i++ {\n    for j := 0; j &lt; num; j++ {\n        if a[i] &lt; a[j] {\n            a[i], a[j] = a[j], a[i] \/\/ \u771f\u7684\u65b9\u4fbf\uff0c\u800c\u4e14\u4e0d\u7528\u518d\u5b9a\u4e49\u4e00\u4e2atemp\n        }\n    }\n}\nfmt.Println(&quot;\u6392\u5e8f\u540e&quot;, a)<\/code><\/pre>\n<h3>\u5207\u7247Slice<\/h3>\n<p>\u5207\u7247\u4e3a\u5f15\u7528\u7c7b\u578b\uff0c\u5176\u4f5c\u4e3a\u53d8\u957f\u6570\u7ec4\u7684\u66ff\u4ee3\u65b9\u6848\uff0c\u53ef\u4ee5\u5173\u8054\u5e95\u5c42\u6570\u7ec4\u7684\u5c40\u90e8\u6216\u5168\u90e8\uff0c\u53ef\u4ee5\u76f4\u63a5\u521b\u5efa\u6216\u4ece\u5e95\u5c42\u6570\u7ec4\u83b7\u53d6\u751f\u6210<\/p>\n<p>\u5982\u679c\u591a\u4e2aslice\u6307\u5411\u76f8\u540c\u7684\u5e95\u5c42\u6570\u7ec4\uff0c\u5176\u4e2d\u4e00\u4e2a\u7684\u503c\u6539\u53d8\u4f1a\u5f71\u54cd\u5168\u90e8<\/p>\n<p>\u58f0\u660e\u5207\u7247\u548c\u6570\u7ec4\u7c7b\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u4e2d\u62ec\u53f7\u91cc\u662f\u7a7a\u7684<\/p>\n<pre><code class=\"language-go\">var s []int \/\/ \u6253\u5370\u51fa\u6765\u662f []<\/code><\/pre>\n<p>slice\u4ece\u6570\u7ec4\u4e2d\u53d6\u5143\u7d20<\/p>\n<pre><code class=\"language-go\">a := [10]int{0,1,2,3,4,5,6,7,8,9}\ns := a[5] \/\/ \u53d6\u7d22\u5f15\u4e3a5\u7684\u503c\uff0c\u6253\u5370\u51fa\u6765\u662f 5\ns := a[5: 10] \/\/ \u8303\u56f4\u5de6\u95ed\u53f3\u5f00\uff0c\u5373\u53d6\u7d22\u5f155\u52309\u7684\u6570\u636e\uff0c\u6253\u5370\u51fa\u6765\u662f [5,6,7,8,9]\ns := a[5:] \/\/ \u7ed3\u679c\u548c\u4e0a\u9762\u4e00\u6837\ns := a[:5] \/\/ \u53d6\u524d\u4e94\u4e2a\u5143\u7d20\uff0c\u4f9d\u7136\u662f\u5de6\u95ed\u53f3\u5f00\uff0c\u6253\u5370\u51fa\u6765\u662f [0,1,2,3,4]<\/code><\/pre>\n<p>\u5207\u7247\u6bd4\u8f83\u6b63\u5f0f\u7684\u521b\u5efa\u662f\u4f7f\u7528make\u521b\u5efa<\/p>\n<pre><code class=\"language-go\">make([]T, len, cap) \/\/ len\u8868\u793a\u5b58\u50a8\u5143\u7d20\u7684\u4e2a\u6570\uff0ccap\u8868\u793a\u5bb9\u91cf\uff0ccap\u53ef\u4ee5\u7701\u7565\uff0c\u7701\u7565\u4ee3\u8868cap\u548clen\u7684\u503c\u4e00\u6837<\/code><\/pre>\n<p>\u8865\u5145\uff1a\u51fd\u6570\u4f20\u53c2\u4fee\u6539slice\u65f6\u63a8\u8350\u4f7f\u7528\u8fd4\u56de<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\nfunc Keng(s []int) []int {\n    s = append(s, 3)\n    return s\n}\nfunc main() {\n    s := make([]int, 0)\n    fmt.Println(s)\n    s = Keng(s)\n    fmt.Println(s)\n}\n\/* \u8f93\u51fa\u7ed3\u679c\n[]\n[3]\n*\/<\/code><\/pre>\n<p>make\u65f6slice\u7684\u957f\u5ea6\u548c\u5bb9\u91cf\u90fd\u4e3a0\uff0c\u4e3a\u4e86\u907f\u514d\u7a7a\u95f4\u6d6a\u8d39\u53ef\u4ee5\u4f7f\u7528\u8fd4\u56de\u7684\u5f62\u5f0f\u5bf9\u5176\u91cd\u65b0\u8d4b\u503c<\/p>\n<h4>Reslice<\/h4>\n<p>Reslice\u65f6\u7d22\u5f15\u4ee5\u88abslice\u7684\u5207\u7247\u4e3a\u51c6<\/p>\n<p>\u7d22\u5f15\u4e0d\u53ef\u4ee5\u8d85\u8fc7\u88abslice\u7684\u5207\u7247\u7684\u5bb9\u91cfcap0\u503c<\/p>\n<p>\u7d22\u5f15\u8d8a\u754c\u4e0d\u4f1a\u5bfc\u81f4\u5e95\u5c42\u6570\u7ec4\u7684\u91cd\u65b0\u5206\u914d\u800c\u662f\u5f15\u53d1\u9519\u8bef<\/p>\n<pre><code class=\"language-go\">func main() {\n    a := []byte{&#039;a&#039;, &#039;b&#039;, &#039;c&#039;, &#039;d&#039;, &#039;e&#039;, &#039;f&#039;, &#039;g&#039;, &#039;h&#039;, &#039;i&#039;, &#039;j&#039;, &#039;k&#039;}\n    sa := a[2:5]\n    fmt.Println(string(sa)) \/\/ cde\n    fmt.Println(len(sa), cap(sa)) \/\/ 3 9\n    sb := sa[3:5]\n    fmt.Println(string(sb)) \/\/ fg\n}<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/tuchuang.shifengzhi.asia\/picture\/go2.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/tuchuang.shifengzhi.asia\/picture\/go2.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240609120142179\" \/><\/div><\/p>\n<h4>Append<\/h4>\n<p>\u53ef\u4ee5\u5728glice\u5c3e\u90e8\u8ffd\u52a0\u5143\u7d20<\/p>\n<p>\u53ef\u4ee5\u5c06\u4e00\u4e2aslice\u8ffd\u52a0\u5728\u53e6\u4e00\u4e2aslice\u5c3e\u90e8<\/p>\n<pre><code class=\"language-go\">func main() {\n    s1 := make([]int, 3, 6)\n    fmt.Printf(&quot;%p\\n&quot;, s1) \/\/ 0xc00000e3f0\n    s1 = append(s1, 1, 2, 3)\n    fmt.Printf(&quot;%v %p\\n&quot;, s1, s1) \/\/ [0 0 0 1 2 3] 0xc00000e3f0\n    s1 = append(s1, 1, 2, 3)\n    fmt.Printf(&quot;%v %p\\n&quot;, s1, s1) \/\/ [0 0 0 1 2 3 1 2 3] 0xc000016180\n}<\/code><\/pre>\n<p>\u5982\u679c\u6700\u7ec8\u957f\u5ea6\u672a\u8d85\u8fc7\u8ffd\u52a0\u5230slice\u7684\u5bb9\u91cf\u5219\u8fd4\u56de\u539f\u59cbslice<\/p>\n<p>\u5982\u679c\u8d85\u8fc7\u8ffd\u52a0\u5230\u7684slice\u7684\u5bb9\u91cf\u5219\u5c06\u91cd\u65b0\u5206\u914d\u6570\u7ec4\u5e76\u62f7\u8d1d\u539f\u59cb\u6570\u636e<\/p>\n<pre><code class=\"language-go\">func main() {\n    a := []int{1, 2, 3, 4, 5}\n    s1 := a[2:5]\n    s2 := a[1:3]\n    fmt.Println(s1, s2) \/\/ [3 4 5] [2 3]\n    s1[0] = 9\n    fmt.Println(s1, s2) \/\/ [9 4 5] [2 9]\n}<\/code><\/pre>\n<p>slice\u6307\u5411\u6570\u7ec4\uff0c\u672a\u8d85\u51fa\u5bb9\u91cf\u65f6\u4fee\u6539\u5176\u4e2d\u4e00\u4e2a\u7684\u503c\uff0c\u5176\u4ed6\u7684\u503c\u4e5f\u4f1a\u8ddf\u7740\u6539\u53d8<\/p>\n<pre><code class=\"language-go\">func main() {\n    a := []int{1, 2, 3, 4, 5}\n    s1 := a[2:5]\n    s2 := a[1:3]\n    fmt.Println(s1, s2) \/\/ [3 4 5] [2 3]\n    s2 = append(s2, 1, 2, 3, 4, 5)\n    s1[0] = 9\n    fmt.Println(s1, s2) \/\/ [9 4 5] [2 3 1 2 3 4 5]\n}<\/code><\/pre>\n<p>\u8d85\u8fc7\u5bb9\u91cf\u540e\u4f1a\u91cd\u65b0\u5206\u914d\u5730\u5740\uff0c\u4fee\u6539\u5176\u4e2d\u4e00\u4e2a\u7684\u503c\uff0c\u5c06\u4e0d\u4f1a\u5f71\u54cd\u5230\u65b0\u5206\u914d\u7684slice<\/p>\n<h4>copy<\/h4>\n<pre><code class=\"language-go\">func main() {\n    s1 := []int{1, 2, 3, 4, 5}\n    s2 := []int{7, 8, 9}\n    copy(s1, s2)\n    fmt.Println(s1) \/\/ [7 8 9 4 5]\n}<\/code><\/pre>\n<pre><code class=\"language-go\">func main() {\n    s1 := []int{1, 2, 3, 4, 5}\n    s2 := []int{7, 8, 9}\n    copy(s2, s1)\n    fmt.Println(s2) \/\/ [1 2 3]\n}<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u53ea\u62f7\u8d1d\u4e00\u90e8\u5206<\/p>\n<pre><code class=\"language-go\">func main() {\n    s1 := []int{1, 2, 3, 4, 5}\n    s2 := []int{7, 8, 9}\n    copy(s2, s1[:2])\n    fmt.Println(s2) \/\/ [1 2 9]\n}<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u8fd9\u6837<\/p>\n<pre><code class=\"language-go\">func main() {\n    s1 := []int{1, 2, 3, 4, 5}\n    s2 := []int{7, 8, 9}\n    copy(s1[2:4], s2[:2])\n    fmt.Println(s1) \/\/ [1 2 7 8 5]\n}<\/code><\/pre>\n<h3>map<\/h3>\n<p>\u7c7b\u4f3c\u5176\u5b83\u8bed\u8a00\u4e2d\u7684\u54c8\u5e0c\u8868\u6216\u8005\u5b57\u5178\uff0c\u4ee5key-value\u5f62\u5f0f\u5b58\u50a8\u6570\u636e<\/p>\n<p>Key\u5fc5\u987b\u662f\u652f\u6301==\u6216!=\u6bd4\u8f83\u8fd0\u7b97\u7684\u7c7b\u578b\uff0c\u4e0d\u53ef\u4ee5\u662f\u51fd\u6570\u3001map\u6216slice<\/p>\n<p>Map\u67e5\u627e\u6bd4\u7ebf\u6027\u641c\u7d22\u5feb\u5f88\u591a\uff0c\u4f46\u6bd4\u4f7f\u7528\u7d22\u5f15\u8bbf\u95ee\u6570\u636e\u7684\u7c7b\u578b\u6162100\u500d<\/p>\n<p>Map\u4f7f\u7528make0\u521b\u5efa\uff0c\u652f\u6301:=\u8fd9\u79cd\u7b80\u5199\u65b9\u5f0f<\/p>\n<p>make([keyType]valueType,cap)\uff0ccap\u8868\u793a\u5bb9\u91cf\uff0c\u53ef\u7701\u7565<\/p>\n<p>\u8d85\u51fa\u5bb9\u91cf\u65f6\u4f1a\u81ea\u52a8\u6269\u5bb9\uff0c\u4f46\u5c3d\u91cf\u63d0\u4f9b\u4e00\u4e2a\u5408\u7406\u7684\u521d\u59cb\u503c<\/p>\n<p>\u4f7f\u7528len0)\u83b7\u53d6\u5143\u7d20\u4e2a\u6570<\/p>\n<p>\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\u65f6\u81ea\u52a8\u6dfb\u52a0\uff0c\u4f7f\u7528delete0)\u5220\u9664\u67d0\u952e\u503c\u5bf9<\/p>\n<p>\u4f7f\u7528 for range \u5bf9map\u548cslice\u8fdb\u884c\u8fed\u4ee3\u64cd\u4f5c<\/p>\n<pre><code class=\"language-go\">var m map[int]string = make(map[int]string) \/\/ \u58f0\u660emap<\/code><\/pre>\n<pre><code class=\"language-go\">func main() {\n    m := make(map[int]string)\n    m[1] = &quot;go&quot;\n    a := m[1]\n    fmt.Println(a) \/\/ go\n    delete(m, 1)\n    a = m[1]\n    fmt.Println(a) \/\/  (\u8f93\u51fa\u7684\u662f\u7a7a)\n}<\/code><\/pre>\n<p>map\u7684\u503c\u4e3a\u4e00\u4e2amap<\/p>\n<pre><code class=\"language-go\">func main() {\n    var m map[int]map[int]string\n    m = make(map[int]map[int]string)\n    a, ok := m[2][1]\n    fmt.Println(a, ok) \/\/  false (\u8868\u793amap\u6ca1\u6709\u58f0\u660e)\n    if !ok {\n        m[2] = make(map[int]string)\n    }\n    m[2][1] = &quot;OKK&quot;\n    a, ok = m[2][1]\n    fmt.Println(a, ok) \/\/ OKK true (\u8868\u793amap\u58f0\u660e\u4e86)\n}<\/code><\/pre>\n<h4>\u8fed\u4ee3<\/h4>\n<pre><code class=\"language-go\">\/\/ \u8fed\u4ee3slice\nfor i,v := range slice {\n    \/\/ i\u662f\u7d22\u5f15\uff0cv\u662fslice\u7684\u62f7\u8d1d\n}\n\/\/ \u8fed\u4ee3map\nfor i,v := range map {\n    \/\/ i\u662f\u952e\uff0cv\u662fmap\u7684\u62f7\u8d1d\n}<\/code><\/pre>\n<p>v\u53ea\u662f\u4e00\u4e2a\u62f7\u8d1d\uff0c\u5bf9v\u64cd\u4f5c\u4e0d\u4f1a\u5f71\u54cdslice(map)\u672c\u8eab<\/p>\n<pre><code class=\"language-go\">func main() {\n    sm := make([]map[int]string, 5)\n    for _, v := range sm {\n        v = make(map[int]string, 1)\n        v[1] = &quot;OK&quot;\n        fmt.Println(v)\n    }\n    fmt.Println(sm)\n}\n\/* \u8f93\u51fa\u7ed3\u679c\nmap[1:OK]\nmap[1:OK]\nmap[1:OK]\nmap[1:OK]\nmap[1:OK]\n[map[] map[] map[] map[] map[]]\n*\/<\/code><\/pre>\n<p>\u4e0a\u9762\u5e76\u4e0d\u4f1a\u5f71\u54cd\u5207\u7247map\u672c\u8eab\uff0c\u5982\u679c\u60f3\u64cd\u4f5c\u5176\u672c\u8eab\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u4ee3\u7801<\/p>\n<pre><code class=\"language-go\">func main() {\n    sm := make([]map[int]string, 5)\n    for i := range sm {\n        sm[i] = make(map[int]string, 1)\n        sm[i][1] = &quot;OK&quot;\n        fmt.Println(sm[i])\n    }\n    fmt.Println(sm)\n}\n\/* \u8f93\u51fa\u7ed3\u679c\nmap[1:OK]\nmap[1:OK]\nmap[1:OK]\nmap[1:OK]\nmap[1:OK]\n[map[1:OK] map[1:OK] map[1:OK] map[1:OK] map[1:OK]]\n*\/<\/code><\/pre>\n<p><strong>\u5bf9map\u5b9e\u73b0\u95f4\u63a5\u6392\u5e8f<\/strong><\/p>\n<pre><code class=\"language-go\">func main() {\n    m := map[int]string{1: &quot;a&quot;, 2: &quot;b&quot;, 3: &quot;c&quot;, 4: &quot;d&quot;, 5: &quot;e&quot;}\n    s := make([]int, len(m))\n    i := 0\n    for k, _ := range m {\n        s[i] = k\n        i++\n    }\n    sort.Ints(s) \/\/ \u5bf9\u6574\u578b\u8fdb\u884c\u6392\u5e8f\n    fmt.Println(s)\n}<\/code><\/pre>\n<p>\u8fed\u4ee3map\u53d6\u51fa\u7684key\u987a\u5e8f\u662f\u968f\u673a\u7684\uff0c\u5c06\u53d6\u51fa\u7684key\u653e\u5165slice\u4e2d\uff0c\u518d\u5bf9\u5176\u6392\u5e8f\u53ef\u4ee5\u5b9e\u73b0\u95f4\u63a5\u5bf9map\u7684key\u8fdb\u884c\u6392\u5e8f<\/p>\n<p><strong>\u5c06map\u7684key\u548cvalue\u5bf9\u8c03<\/strong><\/p>\n<pre><code class=\"language-go\">func main() {\n    m := map[int]string{1: &quot;a&quot;, 2: &quot;b&quot;, 3: &quot;c&quot;, 4: &quot;d&quot;, 5: &quot;e&quot;}\n    fmt.Println(m) \/\/ map[1:a 2:b 3:c 4:d 5:e]\n    m2 := make(map[string]int)\n    for k, v := range m {\n        m2[v] = k\n    }\n    fmt.Println(m2) \/\/ map[a:1 b:2 c:3 d:4 e:5]\n}<\/code><\/pre>\n<h3>\u51fd\u6570function<\/h3>\n<p>Go \u51fd\u6570 \u4e0d\u652f\u6301 \u5d4c\u5957\u3001\u91cd\u8f7d\u548c\u9ed8\u8ba4\u53c2\u6570<\/p>\n<p>\u4f46\u652f\u6301\u4ee5\u4e0b\u7279\u6027\uff1a<\/p>\n<ul>\n<li>\u65e0\u9700\u58f0\u660e\u539f\u578b:\u4e0d\u5b9a\u957f\u5ea6\u53d8\u53c2\u3001\u591a\u8fd4\u56de\u503c\u3001\u547d\u540d\u8fd4\u56de\u503c\u53c2\u6570<\/li>\n<li>\u533f\u540d\u51fd\u6570\u3001\u95ed\u5305<\/li>\n<\/ul>\n<p>\u5b9a\u4e49\u51fd\u6570\u4f7f\u7528\u5173\u952e\u5b57 func\uff0c\u4e14\u5de6\u5927\u62ec\u53f7\u4e0d\u80fd\u53e6\u8d77\u4e00\u884c<\/p>\n<p>\u51fd\u6570\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u79cd\u7c7b\u578b\u4f7f\u7528<\/p>\n<pre><code class=\"language-go\">\/\/ \u4e0d\u5b9a\u957f\u5ea6\u53d8\u53c2 \u76f8\u5f53\u4e8e\u62f7\u8d1d\u4e00\u4efd\u5e76\u653e\u5165slice\u4e2d \u4e0d\u5b9a\u957f\u5ea6\u53d8\u53c2\u53ea\u80fd\u653e\u5728\u53c2\u6570\u6700\u540e\u9762\nfunc A(b string, a ...int){\n    fmt.Println(a)\n}\n\/\/ \u591a\u8fd4\u56de\u503c \u547d\u540d\u8fd4\u56de\u503c\u53c2\u6570\nfunc A() (a,b,c int){\n    a,b,c = 1,2,3 \/\/ a,b,c\u5df2\u7ecf\u58f0\u660e\u8fc7\u4e86\uff0c\u8fd9\u91cc\u53ef\u4ee5\u76f4\u63a5\u8d4b\u503c\n    return \/\/ \u4e0a\u9762\u8fd4\u56de\u503c\u5904\u5df2\u7ecf\u58f0\u660e\u4e86\u8981\u8fd4\u56de\u7684a,b,c\uff0c\u8fd9\u91cc\u53ef\u4ee5\u7701\u7565\n}\n\/\/ \u533f\u540d\u51fd\u6570\na := func(){\n    fmt.Println(&quot;Func&quot;)\n} \/\/ \u53ef\u4ee5\u4f7f\u7528a()\u6765\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570<\/code><\/pre>\n<p>\u533f\u540d\u51fd\u6570\u4e0d\u80fd\u4f5c\u4e3a\u9876\u7ea7\u51fd\u6570\uff0c\u4e5f\u5c31\u662f\u4e0d\u80fd\u4f5c\u4e3a\u6700\u5916\u5c42\u51fd\u6570<\/p>\n<p><strong>\u95ed\u5305<\/strong><\/p>\n<pre><code class=\"language-go\">func main() {\n    f := closure(10)\n    fmt.Println(f(1)) \/\/ \n    fmt.Println(f(2)) \/\/ \n}\n\nfunc closure(x int) func(int) int {\n    fmt.Printf(&quot;%p\\n&quot;, &amp;x) \/\/ \n    return func(y int) int {\n        fmt.Printf(&quot;%p\\n&quot;, &amp;x) \/\/ \n        return x + y\n    }\n}\n\/* \u8f93\u51fa\u7ed3\u679c\n0xc000096068\n0xc000096068\n11\n0xc000096068\n12\n*\/<\/code><\/pre>\n<h4>defer<\/h4>\n<p>defer\u7684\u6267\u884c\u65b9\u5f0f\u7c7b\u4f3c\u5176\u5b83\u8bed\u8a00\u4e2d\u7684\u6790\u6784\u51fd\u6570\uff0c\u5728\u51fd\u6570\u4f53\u6267\u884c\u7ed3\u675f\u540e<\/p>\n<p>\u6309\u7167\u8c03\u7528\u987a\u5e8f\u7684\u76f8\u53cd\u987a\u5e8f\u9010\u4e2a\u6267\u884c<\/p>\n<p>\u5373\u4f7f\u51fd\u6570\u53d1\u751f\u4e25\u91cd\u9519\u8bef\u4e5f\u4f1a\u6267\u884c<\/p>\n<p>\u652f\u6301\u533f\u540d\u51fd\u6570\u7684\u8c03\u7528<\/p>\n<p>\u5e38\u7528\u4e8e\u8d44\u6e90\u6e05\u7406\u3001\u6587\u4ef6\u5173\u95ed\u3001\u89e3\u9501\u4ee5\u53ca\u8bb0\u5f55\u65f6\u95f4\u7b49\u64cd\u4f5c<\/p>\n<p>\u901a\u8fc7\u4e0e\u533f\u540d\u51fd\u6570\u914d\u5408\u53ef\u5728return\u4e4b\u540e\u4fee\u6539\u51fd\u6570\u8ba1\u7b97\u7ed3\u679c<\/p>\n<p>\u5982\u679c\u51fd\u6570\u4f53\u5185\u67d0\u4e2a\u53d8\u91cf\u4f5c\u4e3adefer\u65f6\u533f\u540d\u51fd\u6570\u7684\u53c2\u6570\uff0c\u5219\u5728\u5b9a\u4e49defer<\/p>\n<p>\u65f6\u5373\u5df2\u7ecf\u83b7\u5f97\u4e86\u62f7\u8d1d\uff0c\u5426\u5219\u5219\u662f\u5f15\u7528\u67d0\u4e2a\u53d8\u91cf\u7684\u5730\u5740<\/p>\n<p>Go \u6ca1\u6709\u5f02\u5e38\u673a\u5236\uff0c\u4f46\u6709 panic\/recover \u6a21\u5f0f\u6765\u5904\u7406\u9519\u8bef<\/p>\n<p>Panic \u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u5f15\u53d1\uff0c\u4f46recover<strong>\u53ea\u6709<\/strong>\u5728defer\u8c03\u7528\u7684\u51fd\u6570\u4e2d\u6709\u6548<\/p>\n<pre><code class=\"language-go\">for i := 0; i &lt; 3; i++ {\n    defer fmt.Println(i)\n}<\/code><\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u6253\u5370\u7ed3\u679c\u4e3a2 1 0\uff0cdefer\u5148\u8fdb\u540e\u51fa\uff0c\u4e3a\u6808\u7ed3\u6784<\/p>\n<p>defer\u4e0e\u95ed\u5305\u4e00\u8d77\u4f7f\u7528<\/p>\n<pre><code class=\"language-go\">for i := 0; i &lt; 3; i++ {\n    defer func() {\n        fmt.Println(i)\n    }() \/\/ \u81ea\u6267\u884c\u51fd\u6570\uff0c\u5982\u679c\u628a\u524d\u9762\u7684\u533f\u540d\u51fd\u6570\u8d4b\u7ed9\u53d8\u91cfa\uff0c\u5c31\u548ca()\u4e00\u6837\u4e86\n}<\/code><\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u6267\u884c\u7ed3\u679c\u4e3a3 3 3\uff0c\u5185\u5c42\u51fd\u6570\u6ca1\u6709i\uff0c\u5411\u5916\u5c42\u5bfb\u627e\u627e\u5230\u4e86i\uff0c\u62ff\u5230\u4e86i\u7684\u5f15\u7528\u4e5f\u5c31\u662fi\u7684\u5730\u5740\uff0c\u5faa\u73af\u7ed3\u675f\u65f6i\u4e3a3\uff0c\u6240\u4ee5\u95ed\u5305\u8c03\u7528i\u7684\u90fd\u4e3a3<\/p>\n<p><strong>panic\u4e0erecover<\/strong><\/p>\n<pre><code class=\"language-go\">func main() {\n    A()\n    B()\n    C()\n}\nfunc A() {\n    fmt.Println(&quot;func A&quot;)\n}\nfunc B() {\n    panic(&quot;panic in B&quot;)\n}\nfunc C() {\n    fmt.Println(&quot;func C&quot;)\n}\n\/* \u8f93\u51fa\u7ed3\u679c\nfunc A\npanic: panic in B\n\u62a5\u9519\n*\/<\/code><\/pre>\n<p>\u8c03\u7528panic\u4e4b\u540e\u7a0b\u5e8f\u4e0d\u4f1a\u518d\u6267\u884c\u540e\u9762\u7684\u5185\u5bb9\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u53ef\u4ee5\u4f7f\u7528recover\u518d\u56de\u590d\u56de\u6765\uff0c\u6ce8\uff1a<strong>recover\u53ea\u6709\u5728defer\u8c03\u7528\u7684\u51fd\u6570\u4e2d\u6709\u6548<\/strong><\/p>\n<pre><code class=\"language-go\">func main() {\n    A()\n    B()\n    C()\n}\nfunc A() {\n    fmt.Println(&quot;func A&quot;) \/\/ func A\n}\nfunc B() {\n    defer func() {\n        if err := recover(); err != nil {\n            fmt.Println(&quot;recover in B&quot;) \/\/ recover in B\n            fmt.Println(err) \/\/ panic in B\n        }\n    }()\n    panic(&quot;panic in B&quot;)\n}\nfunc C() {\n    fmt.Println(&quot;func C&quot;) \/\/ func C\n}<\/code><\/pre>\n<p>\u8c03\u7528recover\u4e4b\u540e\u5c06\u4e0d\u4f1a\u8c03\u7528panic\uff0c\u6253\u5370<code>err<\/code>\u65f6\u4f1a\u8f93\u51fa<code>panic in B<\/code><\/p>\n<h4><strong>\u7591\u95ee\u4ee3\u7801<\/strong><\/h4>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u8f93\u51fa\u7ed3\u679c\u4e0d\u4e00\u81f4<\/p>\n<pre><code class=\"language-go\">func main() {\n    var fs = [4]func(){}\n    for i := 0; i &lt; 4; i++ {\n        defer fmt.Println(&quot;defer i = &quot;, i)\n        defer func() {\n            fmt.Println(&quot;defer_closure i = &quot;, i)\n        }()\n        fs[i] = func() {\n            fmt.Println(&quot;closure i = &quot;, i)\n        }\n    }\n    for _, f := range fs {\n        f()\n    }\n}\n\/* \u8f93\u51fa\u7ed3\u679c\nclosure i =  0\nclosure i =  1\nclosure i =  2\nclosure i =  3\ndefer_closure i =  3\ndefer i =  3\ndefer_closure i =  2\ndefer i =  2\ndefer_closure i =  1\ndefer i =  1\ndefer_closure i =  0\ndefer i =  0\n*\/<\/code><\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u539f\u6765\u7684\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b<\/p>\n<pre><code>closure i =  4\nclosure i =  4\nclosure i =  4\nclosure i =  4\ndefer_closure i =  4\ndefer i =  3\ndefer_closure i =  4\ndefer i =  2\ndefer_closure i =  4\ndefer i =  1\ndefer_closure i =  4\ndefer i =  0<\/code><\/pre>\n<p>\u8fd9\u662f\u4e3a\u4ec0\u4e48\uff0cgo\u53d1\u751f\u4e86\u4ec0\u4e48\u91cd\u5927\u7684\u6539\u53d8\u5417\uff1f<\/p>\n<h3>\u7ed3\u6784struct<\/h3>\n<p>Go \u4e2d\u7684struct\u4e0eC\u4e2d\u7684struct\u975e\u5e38\u76f8\u4f3c\uff0c\u5e76\u4e14Go\u6ca1\u6709class<\/p>\n<p>\u4f7f\u7528 type<Name>struct{} \u5b9a\u4e49\u7ed3\u6784\uff0c\u540d\u79f0\u9075\u5faa\u53ef\u89c1\u6027\u89c4\u5219<\/p>\n<p>\u652f\u6301\u6307\u5411\u81ea\u8eab\u7684\u6307\u9488\u7c7b\u578b\u6210\u5458<\/p>\n<p>\u652f\u6301\u533f\u540d\u7ed3\u6784\uff0c\u53ef\u7528\u4f5c\u6210\u5458\u6216\u5b9a\u4e49\u6210\u5458\u53d8\u91cf<\/p>\n<p>\u533f\u540d\u7ed3\u6784\u4e5f\u53ef\u4ee5\u7528\u4e8emap\u7684\u503c<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u5b57\u9762\u503c\u5bf9\u7ed3\u6784\u8fdb\u884c\u521d\u59cb\u5316<\/p>\n<p>\u5141\u8bb8\u76f4\u63a5\u901a\u8fc7\u6307\u9488\u6765\u8bfb\u5199\u7ed3\u6784\u6210\u5458<\/p>\n<p>\u76f8\u540c\u7c7b\u578b\u7684\u6210\u5458\u53ef\u8fdb\u884c\u76f4\u63a5\u62f7\u8d1d\u8d4b\u503c<\/p>\n<p>\u652f\u6301 ==\u4e0e!=\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff0c\u4f46\u4e0d\u652f\u6301&gt;\u6216&lt;<\/p>\n<p>\u652f\u6301\u533f\u540d\u5b57\u6bb5\uff0c\u672c\u8d28\u4e0a\u662f\u5b9a\u4e49\u4e86\u4ee5\u67d0\u4e2a\u7c7b\u578b\u540d\u4e3a\u540d\u79f0\u7684\u5b57\u6bb5<\/p>\n<p>\u5d4c\u5165\u7ed3\u6784\u4f5c\u4e3a\u533f\u540d\u5b57\u6bb5\u770b\u8d77\u6765\u50cf\u7ee7\u627f\uff0c\u4f46\u4e0d\u662f\u7ee7\u627f<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u533f\u540d\u5b57\u6bb5\u6307\u9488<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\ntype person struct {\n    Name string\n    Age  int\n}\n\nfunc main() {\n    a := person{\n        Name: &quot;jojo&quot;,\n    }\n    a.Age = 19\n    fmt.Println(a)\n    A(a)\n    fmt.Println(a)\n}\nfunc A(per person) {\n    per.Age = 12\n    fmt.Println(&quot;func A&quot;, per)\n}\n\/* \u8f93\u51fa\u7ed3\u679c\n{jojo 19}\nfunc A {jojo 12}\n{jojo 19}\n*\/<\/code><\/pre>\n<p>\u5728\u51fd\u6570A\u4e2d\u53ea\u662f\u4e00\u4e2a\u503c\u62f7\u8d1d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6307\u9488\u6765\u4fee\u6539\u539f\u503c\uff0c\u53d8\u6210\u5f15\u7528<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\ntype person struct {\n    Name string\n    Age  int\n}\n\nfunc main() {\n    a := person{&quot;jojo&quot;, 19} \/\/ \u4e5f\u53ef\u4ee5\u76f4\u63a5\u8fd9\u6837\u8d4b\u503c\n    fmt.Println(a)\n    A(&amp;a)\n    fmt.Println(a)\n}\nfunc A(per *person) {\n    per.Age = 12\n    fmt.Println(&quot;func A&quot;, per)\n}\n\/* \u8f93\u51fa\u7ed3\u679c\n{jojo 19}\nfunc A &amp;{jojo 12}\n{jojo 12}\n*\/<\/code><\/pre>\n<p>\u5728go\u4e2d\u54ea\u6015\u53d6\u4e86\u5730\u5740\uff0c\u4e5f\u53ef\u4ee5\u50cf\u4e4b\u524d\u4e00\u6837\u4fee\u6539\u503c\uff0c\u5982\u4e0b<\/p>\n<pre><code class=\"language-go\">a := &amp;person{\n    Name: &quot;jojo&quot;\n}\na.Name = &quot;Dio&quot; \/\/ \u5b8c\u5168\u53ef\u4ee5\u5e76\u4e14\u662f\u6b63\u786e\u7684\uff0c\u8fd9\u662fgo\u65b9\u4fbf\u7684\u5730\u65b9<\/code><\/pre>\n<p>\u533f\u540d\u7ed3\u6784<\/p>\n<pre><code class=\"language-go\">a := struct {\n    Name string\n    Age int\n}{\n    Name: &quot;jojo&quot;,\n    Age: 19,\n}<\/code><\/pre>\n<p>go\u4e2d\u7684\u7ec4\u5408\uff0c\u5bf9\u6807\u7ee7\u627f\u7684\u5b58\u5728<\/p>\n<pre><code class=\"language-go\">type human struct{\n    Sex int\n}\ntype teacher struct{\n    human\n    Name string\n    Age int\n}\ntype student struct {\n    human\n    Name string\n    Age int\n}\nfunc main(){ \n    a := teacher{Name: &quot;joe&quot;,Age: 19,human: human{Sex: 0}}\n    b := student{Name: &quot;joe&quot;,Age: 20,human: human{Sex: 1}}\n    a.Name = &quot;joe2&quot;\n    a.Age = 13\n    a.human.Sex = 10 \/\/ \u53ef\u4ee5\u8fd9\u6837\n    a.Sex = 100 \/\/ \u4e5f\u53ef\u4ee5\u76f4\u63a5\u8fd9\u6837\n    fmt.Println(a,b)\n}<\/code><\/pre>\n<h3>\u65b9\u6cd5method<\/h3>\n<p>Go \u4e2d\u867d\u6ca1\u6709class\uff0c\u4f46\u4f9d\u65e7\u6709method<\/p>\n<p>\u901a\u8fc7\u663e\u793a\u8bf4\u660ereceiver\u6765\u5b9e\u73b0\u4e0e\u67d0\u4e2a\u7c7b\u578b\u7684\u7ec4\u5408<\/p>\n<p>\u53ea\u80fd\u4e3a\u540c\u4e00\u4e2a\u5305\u4e2d\u7684\u7c7b\u578b\u5b9a\u4e49\u65b9\u6cd5<\/p>\n<p>Receiver\u53ef\u4ee5\u662f\u7c7b\u578b\u7684\u503c\u6216\u8005\u6307\u9488<\/p>\n<p>\u4e0d\u5b58\u5728\u65b9\u6cd5\u91cd\u8f7d<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u503c\u6216\u6307\u9488\u6765\u8c03\u7528\u65b9\u6cd5\uff0c\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u5b8c\u6210\u8f6c\u6362<\/p>\n<p>\u4ece\u67d0\u79cd\u610f\u4e49\u4e0a\u6765\u8bf4\uff0c\u65b9\u6cd5\u662f\u51fd\u6570\u7684\u8bed\u6cd5\u7cd6\uff0c\u56e0\u4e3areceiver\u5176\u5b9e\u5c31\u662f\u65b9\u6cd5\u6240\u63a5\u6536\u7684\u7b2c1\u4e2a\u53c2\u6570(Method Valuevs\uff0cMethod Expression)<\/p>\n<p>\u5982\u679c\u5916\u90e8\u7ed3\u6784\u548c\u5d4c\u5165\u7ed3\u6784\u5b58\u5728\u540c\u540d\u65b9\u6cd5\uff0c\u5219\u4f18\u5148\u8c03\u7528\u5916\u90e8\u7ed3\u6784\u7684\u65b9\u6cd5<\/p>\n<p>\u7c7b\u578b\u522b\u540d\u4e0d\u4f1a\u62e5\u6709\u5e95\u5c42\u7c7b\u578b\u6240\u9644\u5e26\u7684\u65b9\u6cd5<\/p>\n<p>\u65b9\u6cd5\u53ef\u4ee5\u8c03\u7528\u7ed3\u6784\u4e2d\u7684\u975e\u516c\u5f00\u5b57\u6bb5<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\ntype A struct {\n    Name string\n}\ntype B struct {\n    Name string\n}\n\nfunc main() {\n    a := A{}\n    a.Print() \/\/ A\n    fmt.Println(a.Name) \/\/ AA\n    b := B{}\n    b.Print() \/\/ B\n    fmt.Println(b.Name) \/\/ \u8f93\u51fa\u662f\u7a7a\uff0c\u56e0\u4e3aName\u6ca1\u6709\u503c\n}\nfunc (a *A) Print() {\n    a.Name = &quot;AA&quot;\n    fmt.Println(&quot;A&quot;)\n}\nfunc (b B) Print() {\n    b.Name = &quot;BB&quot;\n    fmt.Println(&quot;B&quot;)\n}<\/code><\/pre>\n<p>\u7c7b\u578b\u522b\u540d\u4e5f\u53ef\u4ee5\u7ed1\u5b9a\u65b9\u6cd5<\/p>\n<pre><code class=\"language-go\">type TZ int\nfunc main(){\n    var a TZ\n    a.Print() \/\/ TZ\n}\nfunc (a *TZ)Print(){\n    fmt.Println(&quot;TZ&quot;)\n}<\/code><\/pre>\n<p>\u8fd8\u53ef\u4ee5\u8fd9\u6837<\/p>\n<pre><code class=\"language-go\">type TZ int\nfunc main(){\n    var a TZ\n    a.Print() \/\/ Method Valuevs\n    (*TZ).Print(&amp;a) \/\/ Method Expression\n}\nfunc (a *TZ)Print(){\n    fmt.Println(&quot;TZ&quot;)\n}\n\/* \u8f93\u51fa\u7ed3\u679c\nTZ\nTZ\n*\/<\/code><\/pre>\n<h3>\u63a5\u56d7interface<\/h3>\n<p>\u63a5\u53e3\u662f\u4e00\u4e2a\u6216\u591a\u4e2a\u65b9\u6cd5\u7b7e\u540d\u7684\u96c6\u5408<\/p>\n<p>\u53ea\u8981\u67d0\u4e2a\u7c7b\u578b\u62e5\u6709\u8be5\u63a5\u53e3\u7684\u6240\u6709\u65b9\u6cd5\u7b7e\u540d\uff0c\u5373\u7b97\u5b9e\u73b0\u8be5\u63a5\u53e3\uff0c\u65e0\u9700\u663e\u793a<\/p>\n<p>\u58f0\u660e\u5b9e\u73b0\u4e86\u54ea\u4e2a\u63a5\u53e3\uff0c\u8fd9\u79f0\u4e3a Structural Typing<\/p>\n<p>\u63a5\u53e3\u53ea\u6709\u65b9\u6cd5\u58f0\u660e\uff0c\u6ca1\u6709\u5b9e\u73b0\uff0c\u6ca1\u6709\u6570\u636e\u5b57\u6bb5<\/p>\n<p>\u63a5\u53e3\u53ef\u4ee5\u533f\u540d\u5d4c\u5165\u5176\u5b83\u63a5\u53e3\uff0c\u6216\u5d4c\u5165\u5230\u7ed3\u6784\u4e2d<\/p>\n<p>\u5c06\u5bf9\u8c61\u8d4b\u503c\u7ed9\u63a5\u53e3\u65f6\uff0c\u4f1a\u53d1\u751f\u62f7\u8d1d\uff0c\u800c\u63a5\u53e3\u5185\u90e8\u5b58\u50a8\u7684\u662f\u6307\u5411\u8fd9\u4e2a<\/p>\n<p>\u590d\u5236\u54c1\u7684\u6307\u9488\uff0c\u65e2\u65e0\u6cd5\u4fee\u6539\u590d\u5236\u54c1\u7684\u72b6\u6001\uff0c\u4e5f\u65e0\u6cd5\u83b7\u53d6\u6307\u9488<\/p>\n<p>\u53ea\u6709\u5f53\u63a5\u53e3\u5b58\u50a8\u7684\u7c7b\u578b\u548c\u5bf9\u8c61\u90fd\u4e3anil\u65f6\uff0c\u63a5\u53e3\u624d\u7b49\u4e8enil<\/p>\n<p>\u63a5\u53e3\u8c03\u7528\u4e0d\u4f1a\u505areceiver\u7684\u81ea\u52a8\u8f6c\u6362<\/p>\n<p>\u63a5\u53e3\u540c\u6837\u652f\u6301\u533f\u540d\u5b57\u6bb5\u65b9\u6cd5<\/p>\n<p>\u63a5\u53e3\u4e5f\u53ef\u5b9e\u73b0\u7c7b\u4f3cOOP\u4e2d\u7684\u591a\u6001<\/p>\n<p>\u7a7a\u63a5\u53e3\u53ef\u4ee5\u4f5c\u4e3a\u4efb\u4f55\u7c7b\u578b\u6570\u636e\u7684\u5bb9\u5668<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\ntype USB interface {\n    Name() string\n    Connecter\n}\ntype Connecter interface {\n    Connect()\n}\n\ntype PhoneConnecter struct {\n    name string\n}\n\nfunc (pc PhoneConnecter) Name() string {\n    return pc.name\n}\nfunc (pc PhoneConnecter) Connect() {\n    fmt.Println(&quot;Connected:&quot;, pc.name)\n}\nfunc main() {\n    a := PhoneConnecter{&quot;PhoneConnecter&quot;}\n    a.Connect()\n    Disconnect(a)\n}\n\nfunc Disconnect(usb USB) {\n    if pc, ok := usb.(PhoneConnecter); ok {\n        fmt.Println(&quot;Disconnect:&quot;, pc.name)\n        return\n    }\n    fmt.Println(&quot;Unknown decive&quot;)\n}\n\/* \u8f93\u51fa\u7ed3\u679c\nConnected: PhoneConnecter\nDisconnect: PhoneConnecter\n*\/<\/code><\/pre>\n<p>\u50cfObject\u4e00\u6837\uff0cgo\u4e2d\u4e5f\u53ef\u4ee5\u770b\u4f5c\u6240\u6709\u7ed3\u6784\u90fd\u201c\u7ee7\u627f\u201d\u4e86\u7a7a\u7684\u63a5\u53e3<\/p>\n<pre><code class=\"language-go\">package main\n\nimport &quot;fmt&quot;\n\ntype empty interface{}\ntype USB interface {\n    Name() string\n    Connecter\n}\ntype Connecter interface {\n    Connect()\n}\n\ntype PhoneConnecter struct {\n    name string\n}\n\nfunc (pc PhoneConnecter) Name() string {\n    return pc.name\n}\nfunc (pc PhoneConnecter) Connect() {\n    fmt.Println(&quot;Connected:&quot;, pc.name)\n}\nfunc main() {\n    a := PhoneConnecter{&quot;PhoneConnecter&quot;}\n    a.Connect()\n    Disconnect(a)\n}\n\nfunc Disconnect(usb interface{}) {\n    switch v := usb.(type) {\n    case PhoneConnecter:\n        fmt.Println(&quot;Disconnect:&quot;, v.name)\n    default:\n        fmt.Println(&quot;Unknown decive&quot;)\n    }\n}\n\/* \u8f93\u51fa\u7ed3\u679c\nConnected: PhoneConnecter\nDisconnect: PhoneConnecter\n*\/<\/code><\/pre>\n<h3>\u53cd\u5c04reflection<\/h3>\n<p>\u53cd\u5c04\u53ef\u5927\u5927\u63d0\u9ad8\u7a0b\u5e8f\u7684\u7075\u6d3b\u6027\uff0c\u4f7f\u5f97interface{} \u6709\u66f4\u5927\u7684\u53d1\u6325\u4f59\u5730<\/p>\n<p>\u53cd\u5c04\u4f7f\u7528 TypeOf\u548c ValueOf\u51fd\u6570\u4ece\u63a5\u53e3\u4e2d\u83b7\u53d6\u76ee\u6807\u5bf9\u8c61\u4fe1\u606f<\/p>\n<p>\u53cd\u5c04\u4f1a\u5c06\u533f\u540d\u5b57\u6bb5\u4f5c\u4e3a\u72ec\u7acb\u5b57\u6bb5(\u533f\u540d\u5b57\u6bb5\u672c\u8d28)<\/p>\n<p>\u60f3\u8981\u5229\u7528\u53cd\u5c04\u4fee\u6539\u5bf9\u8c61\u72b6\u6001\uff0c\u524d\u63d0\u662finterface.data\u662fsettable\u5373 pointer-interface<\/p>\n<p>\u901a\u8fc7\u53cd\u5c04\u53ef\u4ee5\u201c\u52a8\u6001\u201d\u8c03\u7528\u65b9\u6cd5<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    &quot;fmt&quot;\n    &quot;reflect&quot;\n)\n\ntype User struct {\n    Id   int\n    Name string\n    Age  int\n}\n\nfunc (u User) Hello() {\n    fmt.Println(&quot;hello world&quot;)\n}\n\nfunc main() {\n    u := User{1, &quot;jack&quot;, 20}\n    Info(u)\n}\n\nfunc Info(o interface{}) {\n    t := reflect.TypeOf(o)\n    fmt.Println(&quot;type:&quot;, t.Name())\n    if k := t.Kind(); k != reflect.Struct {\n        fmt.Println(&quot;\u4e0d\u5408\u6cd5\u7684\u7c7b\u578b:&quot;, t.Kind())\n        return\n    }\n    v := reflect.ValueOf(o)\n    fmt.Println(&quot;Fields:&quot;)\n    for i := 0; i &lt; t.NumField(); i++ {\n        f := t.Field(i)\n        val := v.Field(i).Interface()\n        fmt.Printf(&quot;%6s: %v = %v\\n&quot;, f.Name, f.Type, val)\n    }\n    for i := 0; i &lt; t.NumMethod(); i++ {\n        m := t.Method(i)\n        fmt.Printf(&quot;%6s: %v\\n&quot;, m.Name, m.Type)\n    }\n}\n\/* \u8f93\u51fa\u7ed3\u679c\ntype: User\nFields:\n    Id: int = 1\n  Name: string = jack\n   Age: int = 20\n Hello: func(main.User)\n*\/\n\n\/* Info(&amp;u) \u89e6\u53d1if\u62a5\u9519\u7684\u8f93\u51fa\u7ed3\u679c\ntype: \n\u4e0d\u5408\u6cd5\u7684\u7c7b\u578b: ptr\n*\/<\/code><\/pre>\n<p>\u53cd\u5c04\u64cd\u4f5c\u57fa\u672c\u7c7b\u578b<\/p>\n<pre><code class=\"language-go\">func main() {\n    x := 123\n    v := reflect.ValueOf(&amp;x)\n    v.Elem().SetInt(999)\n    fmt.Println(x) \/\/ 999\n}<\/code><\/pre>\n<p>\u53cd\u5c04\u4fee\u6539\u5bf9\u8c61\u5c5e\u6027<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    &quot;fmt&quot;\n    &quot;reflect&quot;\n)\n\ntype User struct {\n    Id   int\n    Name string\n    Age  int\n}\n\nfunc main() {\n    u := User{1, &quot;jack&quot;, 20}\n    Set(&amp;u)\n    fmt.Println(u)\n}\n\nfunc Set(o interface{}) {\n    v := reflect.ValueOf(o)\n    if v.Kind() == reflect.Ptr &amp;&amp; !v.Elem().CanSet() {\n        fmt.Println(&quot;\u7c7b\u578b\u4e0d\u5bf9&quot;)\n        return\n    } else {\n        v = v.Elem()\n    }\n    f := v.FieldByName(&quot;Name&quot;)\n    if !f.IsValid() {\n        fmt.Println(&quot;\u6ca1\u627e\u5230\u8fd9\u4e2a\u5b57\u6bb5&quot;)\n        return\n    }\n    if f.Kind() == reflect.String {\n        f.SetString(&quot;OK&quot;)\n    }\n}\n\/* \u8f93\u51fa\u7ed3\u679c\n{1 OK 20}\n*\/<\/code><\/pre>\n<p>\u901a\u8fc7\u53cd\u5c04\u8c03\u7528\u65b9\u6cd5<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    &quot;fmt&quot;\n    &quot;reflect&quot;\n)\n\ntype User struct {\n    Id   int\n    Name string\n    Age  int\n}\n\nfunc (u User) Hello(Name string) {\n    fmt.Println(&quot;Hello:&quot;, Name, &quot;,\u6211\u662f\uff1a&quot;, u.Name)\n}\n\nfunc main() {\n    u := User{1, &quot;jack&quot;, 20}\n    v := reflect.ValueOf(u)\n    mv := v.MethodByName(&quot;Hello&quot;)\n    args := []reflect.Value{reflect.ValueOf(&quot;joe&quot;)}\n    mv.Call(args)\n}\n\/* \u8f93\u51fa\u7ed3\u679c\nHello: joe ,\u6211\u662f\uff1a jack\n*\/<\/code><\/pre>\n<h3>\u5e76\u53d1concurrency<\/h3>\n<h4>Channel<\/h4>\n<p>Channel\u662f goroutine\u6c9f\u901a\u7684\u6865\u6881\uff0c\u5927\u90fd\u662f\u963b\u585e\u540c\u6b65\u7684<\/p>\n<p>\u901a\u8fc7 make \u521b\u5efa\uff0cclose \u5173\u95ed<\/p>\n<p>Channel\u662f\u5f15\u7528\u7c7b\u578b<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 for range \u6765\u8fed\u4ee3\u4e0d\u65ad\u64cd\u4f5c channel<\/p>\n<p>\u53ef\u4ee5\u8bbe\u7f6e\u5355\u5411\u6216\u53cc\u5411\u901a\u9053<\/p>\n<p>\u53ef\u4ee5\u8bbe\u7f6e\u7f13\u5b58\u5927\u5c0f\uff0c\u5728\u672a\u88ab\u586b\u6ee1\u524d\u4e0d\u4f1a\u53d1\u751f\u963b\u585e<\/p>\n<pre><code class=\"language-go\">func main() {\n    c := make(chan bool)\n    go func() {\n        fmt.Println(&quot;GO GO GO!&quot;) \/\/ GO GO GO!\n        c &lt;- true\n    }()\n    &lt;-c\n}<\/code><\/pre>\n<pre><code class=\"language-go\">func main() {\n    c := make(chan bool)\n    go func() {\n        fmt.Println(&quot;GO GO GO!&quot;)\n        c &lt;- true\n        close(c)\n    }()\n    for v := range c {\n        fmt.Println(v)\n    }\n}\n\/* \u8f93\u51fa\u7ed3\u679c\nGO GO GO!\ntrue\n*\/<\/code><\/pre>\n<p>\u591aCPU\u6838\u6570<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    &quot;fmt&quot;\n    &quot;runtime&quot;\n)\n\nfunc main() {\n    runtime.GOMAXPROCS(runtime.NumCPU())\n    c := make(chan bool, 10)\n    for i := 0; i &lt; 10; i++ {\n        go Go(c, i)\n    }\n    for i := 0; i &lt; 10; i++ {\n        &lt;-c\n    }\n}\nfunc Go(c chan bool, index int) {\n    a := 1\n    for i := 0; i &lt; 10000000; i++ {\n        a += 1\n    }\n    fmt.Println(index, a)\n    c &lt;- true\n}<\/code><\/pre>\n<p>\u53e6\u4e00\u79cd\u65b9\u6cd5\uff0c\u540c\u6b65\u4efb\u52a1\u7ec4<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    &quot;fmt&quot;\n    &quot;runtime&quot;\n    &quot;sync&quot;\n)\n\nfunc main() {\n    runtime.GOMAXPROCS(runtime.NumCPU())\n    wg := sync.WaitGroup{}\n    wg.Add(10)\n    for i := 0; i &lt; 10; i++ {\n        go Go(&amp;wg, i)\n    }\n    wg.Wait()\n}\nfunc Go(wg *sync.WaitGroup, index int) {\n    a := 1\n    for i := 0; i &lt; 10000000; i++ {\n        a += 1\n    }\n    fmt.Println(index, a)\n    wg.Done()\n}<\/code><\/pre>\n<h4>Select<\/h4>\n<p>\u53ef\u5904\u7406\u4e00\u4e2a\u6216\u591a\u4e2achannel \u7684\u53d1\u9001\u4e0e\u63a5\u6536<\/p>\n<p>\u540c\u65f6\u6709\u591a\u4e2a\u53ef\u7528\u7684 channel\u65f6\u6309\u968f\u673a\u987a\u5e8f\u5904\u7406<\/p>\n<p>\u53ef\u7528\u7a7a\u7684 select \u6765\u963b\u585e main \u51fd\u6570<\/p>\n<p>\u53ef\u8bbe\u7f6e\u8d85\u65f6<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    &quot;fmt&quot;\n)\n\nfunc main() {\n    c1, c2 := make(chan int), make(chan string)\n    o := make(chan bool, 2)\n    go func() {\n        for {\n            select {\n            case v, ok := &lt;-c1:\n                if !ok {\n                    o &lt;- true\n                    break\n                }\n                fmt.Println(&quot;c1&quot;, v)\n            case v, ok := &lt;-c2:\n                if !ok {\n                    o &lt;- true\n                    break\n                }\n                fmt.Println(&quot;c2&quot;, v)\n            }\n        }\n    }()\n    c1 &lt;- 1\n    c2 &lt;- &quot;hi&quot;\n    c1 &lt;- 3\n    c2 &lt;- &quot;hello&quot;\n    close(c1)\n    close(c2)\n    for i := 0; i &lt; 2; i++ {\n        &lt;-o\n    }\n}\n\/* \u8f93\u51fa\u7ed3\u679c\nc1 1\nc2 hi\nc1 3\nc2 hello\n*\/<\/code><\/pre>\n<h3>\u5751<\/h3>\n<h4>\u65f6\u95f4time\u7684\u5751<\/h4>\n<p>time.format<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/tuchuang.shifengzhi.asia\/picture\/go3.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/tuchuang.shifengzhi.asia\/picture\/go3.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240615205114208\" \/><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go\u7b80\u4ecb Go\u8bed\u8a00\uff0cGo \u8bed\u8a00\u8d77\u6e90 2007 \u5e74\uff0c\u5e76\u4e8e 2009 \u5e74\u6b63\u5f0f\u5bf9\u5916\u53d1\u5e03\uff0c\u53c8\u79f0\u4e3aGolang\uff0c\u662f\u7531Go [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[27],"class_list":["post-220","post","type-post","status-publish","format-standard","hentry","category-3","tag-go"],"_links":{"self":[{"href":"https:\/\/boki.shifengzhi.top\/index.php?rest_route=\/wp\/v2\/posts\/220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/boki.shifengzhi.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/boki.shifengzhi.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/boki.shifengzhi.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/boki.shifengzhi.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=220"}],"version-history":[{"count":3,"href":"https:\/\/boki.shifengzhi.top\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":223,"href":"https:\/\/boki.shifengzhi.top\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions\/223"}],"wp:attachment":[{"href":"https:\/\/boki.shifengzhi.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boki.shifengzhi.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boki.shifengzhi.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}