{"id":7235,"date":"2022-02-23T16:46:44","date_gmt":"2022-02-23T08:46:44","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=7235"},"modified":"2024-04-15T09:17:59","modified_gmt":"2024-04-15T01:17:59","slug":"go-14","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2022\/02\/23\/go-14\/","title":{"rendered":"Go\u8bed\u8a00\u4e4b\u6587\u4ef6\u4e0e\u76ee\u5f55\u5904\u7406"},"content":{"rendered":"\n<p class=\"has-text-align-center has-normal-font-size wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u4e00\u3001\u4f7f\u7528ioutil \u5305\u8bfb\u5199\u6587\u4ef6<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9274\u4e8e\u5904\u7406\u6587\u4ef6\u662f\u4e00\u79cd\u5f88\u5e38\u89c1\u7684\u4efb\u52a1\uff0c\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86ioutil \u5305\uff0c\u8ba9\u60a8\u80fd\u591f\u5feb\u901f\u6267\u884c\u4f17\u591a\u6d89\u53ca\u8bfb\u5199\u6587\u4ef6\u7684\u64cd\u4f5c\u3002\u5b9e\u9645\u4e0a\uff0c \u8fd9\u4e2a\u5305\u51e0\u4e4e\u5c31\u662f\u4e00\u4e2aOS \u6a21\u5757\u5305\u88c5\u5668\uff0c\u4f7f\u7528\u5b83\u9700\u8981\u7f16\u5199\u7684\u4ee3\u7801\u66f4\u5c11\uff0c\u4e14\u65e0\u987b\u6267\u884c\u6e05\u7406\u64cd\u4f5c\u3002\u5982\u679c\u60a8\u9700\u8981\u6267\u884c\u4e0b\u8ff0\u4efb\u4f55\u64cd\u4f5c\uff0c\u4e14\u65e0\u987b\u505a\u7ec6\u81f4\u7684\u63a7\u5236\uff0c\u5219\u4f7f\u7528ioutil\u5305\u662f\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8bfb\u53d6\u6587\u4ef6<\/li>\n\n\n\n<li>\u5217\u51fa\u76ee\u5f55\u7684\u5185\u5bb9<\/li>\n\n\n\n<li>\u521b\u5efa\u4e34\u65f6\u76ee\u5f55<\/li>\n\n\n\n<li>\u521b\u5efa\u4e34\u65f6\u6587\u4ef6<\/li>\n\n\n\n<li>\u521b\u5efa\u6587\u4ef6<\/li>\n\n\n\n<li>\u5199\u5165\u6587\u4ef6<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>1\u3001\u8bfb\u53d6\u6587\u4ef6<\/strong><\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bfb\u53d6\u6587\u4ef6\u662f\u6700\u5e38\u89c1\u7684\u64cd\u4f5c\u4e4b\u4e00\u3002ioutil \u5305\u63d0\u4f9b\u4e86\u51fd\u6570Readfile \uff0c\u60a8\u53ef\u4f7f\u7528\u5b83\u6765\u5b8c\u6210\u8fd9\u9879\u4efb\u52a1\uff0c\u8fd9\u4e2a\u51fd\u6570\u5c06\u4e00\u4e2a\u6587\u4ef6\u540d\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u4ee5<strong>\u5b57\u8282\u5207\u7247\u7684\u65b9\u5f0f<\/strong>\u8fd4\u56de\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func ReadFile(filename string) (&#91;]byte, error)    \/\/ReadFile\u8868\u793a\u4e00\u6b21\u6027\u8bfb\u53d6\u5168\u90e8\u5185\u5bb9<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u8981\u5c06\u6587\u4ef6\u5185\u5bb9\u4f5c\u4e3a\u5b57\u7b26\u4e32\u4f7f\u7528\uff0c\u5219\u5fc5\u987b\u5c06\u8fd4\u56de\u7684\u5b57\u8282\u5207\u7247\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0clinux\u4e0b\u7684\u8bfb\u53d6\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"346\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/12-4.png\" alt=\"\" class=\"wp-image-7244\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/12-4.png 708w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/12-4-300x147.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/12-4-600x293.png 600w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"85\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/13-5.png\" alt=\"\" class=\"wp-image-7246\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/13-5.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/13-5-300x36.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/13-5-600x72.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">windows\u73af\u5883\u4e0b\u6587\u4ef6\u5185\u5bb9\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"776\" height=\"390\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/14-4.png\" alt=\"\" class=\"wp-image-7250\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/14-4.png 776w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/14-4-300x151.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/14-4-768x386.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/14-4-600x302.png 600w\" sizes=\"auto, (max-width: 776px) 100vw, 776px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u8bfb\u53d6\u6587\u4ef6\u7684\u8def\u5f84\u4e3a\u76f8\u5bf9\u8def\u5f84\uff0cmain.go\u4e0etest\u4e3a\u540c\u7ea7\uff0cabc.txt\u5728test\u76ee\u5f55\u4e0b\uff0c\u76f4\u63a5\u7ed3\u679c\u4e0e\u4e0a\u8ff0\u76f8\u540c\uff0c\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528ioutil \u5305\u4e2d\u7684\u51fd\u6570Readfile \u8bfb\u53d6\u6587\u4ef6\uff0c\u8fd4\u56de\u503c\u662f\u4e00\u4e2a\u5b57\u8282\u5207\u7247\u548c\u9519\u8bef\u4fe1\u606f<\/li>\n\n\n\n<li>\u5224\u65ad\u5982\u679c\u9519\u8bef\u4e0d\u4e3a\u7a7a\uff0c\u901a\u8fc7log.Fatal()\u6253\u5370\u5185\u5bb9<\/li>\n\n\n\n<li>\u5c06\u8fd4\u56de\u7684\u5b57\u8282\u5207\u7247\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u5e76\u6253\u5370<\/li>\n<\/ul>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">log.Fatal()\u51fd\u6570\u529f\u80fd\uff1a1\u3001\u6253\u5370\u8f93\u51fa\u5185\u5bb9   2\u3001\u9000\u51fa\u7a0b\u5e8f   3\u3001defer\u4e0d\u6267\u884c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd8\u6709\u4e00\u4e2a\u51fd\u6570ReadAll()\u4e5f\u5177\u5907\u8bfb\u53d6\u6587\u4ef6\u7684\u529f\u80fd\uff0c\u4f46\u662f\u6b64\u51fd\u6570\u5bb9\u6613\u9020\u6210\u6027\u80fd\u95ee\u9898\uff0c\u8bfb\u53d6\u5185\u5bb9\u5c11\u4f46\u662f\u7533\u8bf7\u4e86\u5f88\u591a\u7684\u5185\u5bb9\uff0c\u7f51\u7edc\u8bf7\u6c42\u5927\u7684\u65f6\u5019\u5bb9\u6613\u9020\u6210\u5185\u5b58\u6d6a\u8d39\u6216\u8005\u6cc4\u9732\uff0c\u56e0\u6b64\u4e0d\u5efa\u8bae\u4f7f\u7528\uff0c\u8bed\u6cd5\u4e3a:   func ReadAll(r io.Reader) ([]byte, error)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>2\u3001\u521b\u5efa\u6587\u4ef6\uff1a<\/strong><\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ioutil\u5305\u8fd8\u63d0\u4f9b\u4e86\u7528\u4e8e\u521b\u5efa\u6587\u4ef6\u7684\u4fbf\u5229\u51fd\u6570WriteFile\uff0c\u8fd9\u4e2a\u51fd\u6570\u8bbe\u8ba1\u7528\u4e8e\u5c06\u6570\u636e\u5199\u5165\u6587\u4ef6\uff0c\u4f46\u4e5f\u53ef\u4f7f\u7528\u5b83\u6765\u521b\u5efa\u6587\u4ef6\uff0c\u51fd\u6570WriteFile \u63a5\u53d7\u4e00\u4e2a\u6587\u4ef6\u540d\u3001\u8981\u5199\u5165\u6587\u4ef6\u7684\u6570\u636e\u4ee5\u53ca\u5e94\u7528\u4e8e\u6587\u4ef6\u7684\u6743\u9650<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6587\u4ef6\u6743\u9650\u662f\u4eceUNIX \u6743\u9650\u884d\u751f\u800c\u6765\u7684\uff0c\u5b83\u4eec\u5bf9\u5e94\u4e8e3 \u7c7b\u7528\u6237\uff1a\u6587\u4ef6\u6240\u6709\u8005\u3001\u4e0e\u6587\u4ef6\u4f4d\u4e8e\u540c\u4e00\u7ec4\u7684\u7528\u6237\u3001\u5176\u4ed6\u7528\u6237\u3002\u5904\u7406\u6587\u4ef6\u65f6\uff0c\u7406\u89e3\u6587\u4ef6\u6743\u9650\u662f\u786e\u4fdd\u5b89\u5168\u7684\u91cd\u8981\u65b9\u9762\uff0c\u56e0\u4e3a\u9519\u8bef\u5730\u8bbe\u7f6e\u6743\u9650\u610f\u5473\u7740\u6570\u636e\u53ef\u80fd\u88ab\u539f\u672c\u4e0d\u5e94\u8be5\u8ba9\u4ed6\u8bfb\u53d6\u7684\u4eba\u83b7\u5f97<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go \u8bed\u8a00\u4f7f\u7528UNIX \u6743\u9650\u7684\u6570\u5b57\u8868\u793a\u6cd5\uff0c\u4e5f\u9075\u5faa421\u89c4\u5219\uff0c\u6bd4\u5982755\u3001644\u7b49\u6743\u9650\uff0c\u5728UNIX \u578b\u7cfb\u7edf\u4e2d\uff0c \u6587\u4ef6\u7684\u9ed8\u8ba4\u6743\u9650\u4e3a0644 \uff0c\u5373\u6240\u6709\u8005\u80fd\u591f\u8bfb\u53d6\u548c\u5199\u5165\uff0c\u800c\u5176\u4ed6\u4eba\u53ea\u80fd\u8bfb\u53d6\u3002\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\u521b\u5efa\u6587\u4ef6\u65f6\uff0c\u5e94\u8003\u8651\u5982\u4f55\u7ed9\u5b83\u6307\u5b9a\u6743\u9650\u3002\u5982\u679c\u4e0d\u786e\u5b9a\u8be5\u5982\u4f55\u6307\u5b9a\u6743\u9650\uff0c\u4f7f\u7528\u9ed8\u8ba4\u7684UNIX\u6743\u9650\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u8868\u793a\u521b\u5efa\u4e00\u4e2a\u7a7a\u6587\u4ef6\uff0c\u8bbe\u7f6e\u6743\u9650\u4e3a0644(0\u8868\u793a\u5341\u8fdb\u5236)\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"300\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/15-4.png\" alt=\"\" class=\"wp-image-7259\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/15-4.png 708w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/15-4-300x127.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/15-4-600x254.png 600w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u4ee3\u7801\u540e\uff0c\u5728\u76ee\u5f55test\u4e0b\u53ef\u4ee5\u770b\u5230\u521b\u5efa\u7684\u7a7a\u6587\u4ef6bb.txt\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"299\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/16-4.png\" alt=\"\" class=\"wp-image-7261\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/16-4.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/16-4-300x127.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/16-4-600x253.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>3\u3001\u5199\u5165\u6587\u4ef6\uff1a<\/strong><\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u51fd\u6570WriteFile \u4e5f\u53ef\u7528\u6765\u5199\u5165\u6587\u4ef6\uff0c\u8981\u5199\u5165\u6587\u4ef6\uff0c\u53ea\u9700\u4f20\u5165\u4e00\u4e9b\u503c\uff0c\u800c\u4e0d\u662f\u4f20\u5165\u7a7a\u5b57\u8282\u5207\u7247\uff0c\u8981\u5c06\u5b57\u7b26\u4e32\u5199\u5165\u6587\u4ef6\uff0c<strong>\u5fc5\u987b\u5148\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u8282\u5207\u7247<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func WriteFile(filename string, data &#91;]byte, perm os.FileMode) error<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u8868\u793a\u5411\u6587\u4ef6cc.txt\u4e2d\u5199\u5165\u6570\u636e\uff0c\u6587\u4ef6\u4e0d\u5b58\u5728\u5c06\u521b\u5efa\uff0c\u5e76\u5199\u5165\u5b57\u7b26\u4e32\u5185\u5bb9\uff0c\u9700\u8981\u5148\u5c06\u5b57\u7b26\u4e32\u8f6c\u6210\u5b57\u8282\u5207\u7247\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"381\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/17-4.png\" alt=\"\" class=\"wp-image-7264\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/17-4.png 708w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/17-4-300x161.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/17-4-600x323.png 600w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u540e\u53ef\u4ee5\u770b\u5230\u5728test\u76ee\u5f55\u4e0b\u751f\u6210\u4e86\u6587\u4ef6cc.txt\uff0c\u5e76\u4e14\u5185\u5bb9\u4e3ahello,world\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"338\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/18-4.png\" alt=\"\" class=\"wp-image-7266\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/18-4.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/18-4-300x143.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/18-4-600x287.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1aWriteFile\u51fd\u6570\u63a5\u6536\u7684\u6587\u4ef6\u6570\u636e\u9700\u8981\u4e3a\u5b57\u8282\u5207\u7247\u6216\u8005\u6570\u7ec4\u7c7b\u578b\uff0c\u5199\u5165\u5185\u5bb9\u4f1a\u8986\u76d6\u539f\u6765\u5185\u5bb9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">4\u3001\u5217\u51fa\u76ee\u5f55\u7684\u5185\u5bb9\uff1a<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u5904\u7406\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\uff0c\u5fc5\u987b\u77e5\u9053\u76ee\u5f55\u7ed3\u6784\u3002ioutil \u5305\u63d0\u4f9b\u4e86\u4fbf\u5229\u51fd\u6570ReadDir\uff0c\u5b83\u63a5\u53d7\u4ee5\u5b57\u7b26\u4e32\u65b9\u5f0f\u6307\u5b9a\u7684\u76ee\u5f55\u540d\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u6309\u6587\u4ef6\u540d\u6392\u5e8f\u7684\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u7684\u7c7b\u578b\u4e3aFilelnfo \uff0c\u5305\u542b\u5982\u4e0b\u4fe1\u606f:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Name \uff1a\u6587\u4ef6\u7684\u540d\u79f0<\/li>\n\n\n\n<li>Size \uff1a\u6587\u4ef6\u7684\u957f\u5ea6\uff0c \u5355\u4f4d\u4e3a\u5b57\u8282<\/li>\n\n\n\n<li>Mode \uff1a \u7528\u4e8c\u8fdb\u5236\u4f4d\u8868\u793a\u7684\u6743\u9650<\/li>\n\n\n\n<li>ModTime\uff1a\u6587\u4ef6\u6700\u540e\u4e00\u4e2a\u88ab\u4fee\u6539\u7684\u65f6\u95f4<\/li>\n\n\n\n<li>IsDir\uff1a\u6587\u4ef6\u662f\u5426\u662f\u76ee\u5f55<\/li>\n\n\n\n<li>Sys \uff1a\u5e95\u5c42\u6570\u636e\u6e90<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func ReadDir(dirname string) (&#91;]os.FileInfo, error)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u8868\u793a\u5217\u51fa\u76ee\u5f55test\u4e0b\u7684\u5185\u5bb9\uff0c\u5e76\u6253\u5370\u540d\u79f0\u3001\u6743\u9650\u3001\u4ee5\u53ca\u5224\u65ad\u662f\u5426\u4e3a\u76ee\u5f55\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"350\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/1-9.png\" alt=\"\" class=\"wp-image-7271\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/1-9.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/1-9-300x148.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/1-9-600x296.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"146\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/2-9.png\" alt=\"\" class=\"wp-image-7273\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/2-9.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/2-9-300x62.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/2-9-600x124.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center has-normal-font-size wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u4e8c\u3001\u901a\u8fc7os\u5305\u8bfb\u5199\u6587\u4ef6<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ioutil \u5305\u53ef\u7528\u4e8e\u6267\u884c\u4e00\u4e9b\u5e38\u89c1\u7684\u6587\u4ef6\u5904\u7406\u64cd\u4f5c\uff0c\u4f46\u8981\u6267\u884c\u66f4\u590d\u6742\u7684\u64cd\u4f5c\uff0c\u5e94\u4f7f\u7528OS \u5305\uff0cOS\u5305\u8fd0\u884c\u5728\u7a0d\u4f4e\u7684\u5c42\u7ea7\uff0c\u56e0\u6b64\u4f7f\u7528\u5b83\u65f6\uff0c\u5fc5\u987b<strong>\u624b\u5de5\u5173\u95ed<\/strong>\u6253\u5f00\u7684\u6587\u4ef6\uff0cioutil \u5305\u4e2d\u7684\u5f88\u591a\u51fd\u6570\u90fd\u662fOS \u5305\u5305\u88c5\u5668\uff0c\u56e0\u6b64\u4f7f\u7528\u65f6\u65e0\u987b\u663e\u5f0f\u5730\u5173\u95ed\u6587\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">1\u3001\u901a\u8fc70pen()\u51fd\u6570\u6765\u8bfb\u53d6\u6587\u4ef6\uff1a<\/mark><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u6253\u5f00\u4e00\u4e2a\u9700\u8981\u88ab\u8bfb\u53d6\u7684\u6587\u4ef6\uff0c\u5982\u679c\u6210\u529f\u8bfb\u53d6\uff0c\u8fd4\u56de\u7684\u6587\u4ef6\u5bf9\u8c61\u5c06\u53ef\u7528\u88ab\u8bfb\u53d6\uff0c\u8be5\u51fd\u6570\u9ed8\u8ba4\u7684\u6743\u9650\u4e3aO_RDONLY\uff0c\u4e5f\u5c31\u662f\u53ea\u5bf9\u6587\u4ef6\u6709\u53ea\u8bfb\u6743\u9650\u3002\u5982\u679c\u6709\u9519\u8bef\uff0c\u5c06\u8fd4\u56de*PathError\u7c7b\u578b\nfunc Open(name string) (*File, error)  <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>os.Open()\u548cos.OpenFile()<\/strong>\u65b9\u6cd5\u90fd\u8fd4\u56de\u4e00\u4e2a*File\u6587\u4ef6\u5bf9\u8c61\uff0c\u8be5\u6587\u4ef6\u5bf9\u8c61\u9ed8\u8ba4\u6709\u5f88\u591a\u65b9\u6cd5\uff0c\u5176\u4e2d\u8bfb\u53d6\u6587\u4ef6\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>f<strong>unc (f *File) Read(b []byte) (n int, err error) <\/strong>\uff1a\u4ece\u6587\u4ef6\u5bf9\u8c61\u4e2d\u8bfb\u53d6\u957f\u5ea6\u4e3ab\u7684\u5b57\u8282\uff0c\u8fd4\u56de\u5f53\u524d\u8bfb\u5230\u7684\u5b57\u8282\u6570\u4ee5\u53ca\u9519\u8bef\u4fe1\u606f\u3002\u56e0\u6b64\u4f7f\u7528\u8be5\u65b9\u6cd5\u9700\u8981\u5148\u521d\u59cb\u5316\u4e00\u4e2a\u7b26\u5408\u5185\u5bb9\u5927\u5c0f\u7684\u7a7a\u7684\u5b57\u8282\u5217\u8868\u3002\u8bfb\u53d6\u5230\u6587\u4ef6\u7684\u672b\u5c3e\u65f6\uff0c\u8be5\u65b9\u6cd5\u8fd4\u56de0\uff0cio.EOF<\/li>\n\n\n\n<li><strong>func (f *File) ReadAt(b []byte, off int64) (n int, err error) <\/strong>\uff1a\u4ece\u6587\u4ef6\u7684off\u504f\u79fb\u91cf\u5f00\u59cb\u8bfb\u53d6\u957f\u5ea6\u4e3ab\u7684\u5b57\u8282\u3002\u8fd4\u56de\u8bfb\u53d6\u5230\u5b57\u8282\u6570\u4ee5\u53ca\u9519\u8bef\u4fe1\u606f\u3002\u5f53\u8bfb\u53d6\u5230\u7684\u5b57\u8282\u6570n\u5c0f\u4e8e\u60f3\u8981\u8bfb\u53d6\u5b57\u8282\u7684\u957f\u5ea6len(b)\u7684\u65f6\u5019\uff0c\u8be5\u65b9\u6cd5\u5c06\u8fd4\u56de\u975e\u7a7a\u7684error\u3002\u5f53\u8bfb\u5230\u6587\u4ef6\u672b\u5c3e\u65f6\uff0cerr\u8fd4\u56deio.EOF<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u8868\u793a\u901a\u8fc7Open()\u51fd\u6570\u6253\u5f00\u6587\u4ef6\uff0c\u5e76\u901a\u8fc7Read()\u65b9\u6cd5\u6765\u83b7\u53d6\u6587\u4ef6\u5bf9\u8c61\u7684\u5185\u5bb9\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"712\" height=\"355\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-4.png\" alt=\"\" class=\"wp-image-7662\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-4.png 712w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-4-300x150.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-4-600x299.png 600w\" sizes=\"auto, (max-width: 712px) 100vw, 712px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"80\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-2.png\" alt=\"\" class=\"wp-image-7664\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-2.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-2-300x34.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-2-600x68.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">2\u3001\u901a\u8fc7os.OpenFile()\u6765\u8bfb\u53d6\u6587\u4ef6<\/mark>\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">OpenFile\u6709\u4e09\u4e2a\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53c2\u65701\uff1a\u6253\u5f00\u6587\u4ef6\u7684\u8def\u5f84<\/li>\n\n\n\n<li>\u53c2\u65702\uff1a\u6253\u5f00\u6a21\u5f0f<\/li>\n\n\n\n<li>\u53c2\u65703\uff1a\u8868\u793a\u6743\u9650\uff0c\u53d6\u503c\u8303\u56f4\uff080-7\uff09\uff0c\u548clinux\u91cc\u64cd\u4f5c\u6587\u4ef6\u90a3\u4e2a\u8bfb\u5199\u4e00\u6837\uff0c\u4f8b\u59820666\u8868\u793a\u53ef\u8bfb\u53ef\u5199<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e38\u89c1\u7684\u6a21\u5f0f\u6709\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">\u53c2\u6570<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u8bf4\u660e<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">O_RDONLY<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u53ea\u8bfb\u65b9\u5f0f\u6253\u5f00<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">O_WRONLY<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u53ea\u5199\u65b9\u5f0f\u6253\u5f00<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">O_RDWR<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u8bfb\u5199\u65b9\u5f0f\u6253\u5f00<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">O_APPEND<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u8ffd\u52a0\u65b9\u5f0f\u6253\u5f00<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">O_CREATE<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u4e0d\u5b58\u5728\uff0c\u5219\u521b\u5efa<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">O_EXCL<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u5982\u679c\u6587\u4ef6\u5b58\u5728\uff0c\u4e14\u6807\u5b9a\u4e86O_CREATE\u7684\u8bdd\uff0c\u5219\u4ea7\u751f\u4e00\u4e2a\u9519\u8bef<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">O_TRUNC<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u5982\u679c\u6587\u4ef6\u5b58\u5728\uff0c\u5c06\u6587\u4ef6\u6e05\u7a7a<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">O_NOCTTY<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u5982\u679c\u6587\u4ef6\u540d\u4ee3\u8868\u4e00\u4e2a\u7ec8\u7aef\u8bbe\u5907\uff0c\u5219\u4e0d\u628a\u8be5\u8bbe\u5907\u8bbe\u4e3a\u8c03\u7528\u8fdb\u7a0b\u7684\u63a7\u5236\u8bbe\u5907<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">O_NONBLOCK<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u5982\u679c\u6587\u4ef6\u540d\u4ee3\u8868\u4e00\u4e2aFIFO,\u6216\u4e00\u4e2a\u5757\u8bbe\u5907\uff0c\u5b57\u7b26\u8bbe\u5907\u6587\u4ef6\uff0c\u5219\u5728\u4ee5\u540e\u7684\u6587\u4ef6\u53caI\/O\u64cd\u4f5c\u4e2d\u7f6e\u4e3a\u975e\u963b\u585e\u6a21\u5f0f<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">O_SYNC<\/td><td class=\"has-text-align-center\" data-align=\"center\">\u5f53\u8fdb\u884c\u4e00\u7cfb\u5217\u5199\u64cd\u4f5c\u65f6\uff0c\u6bcf\u6b21\u90fd\u8981\u7b49\u5f85\u4e0a\u6b21\u7684I\/O\u64cd\u4f5c\u5b8c\u6210\u518d\u8fdb\u884c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>func OpenFile(name string, flag int, perm FileMode) (*File, error)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u8868\u793a\u6253\u5f00\u6587\u4ef6aa.txt\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5c31\u521b\u5efa\uff0c\u6587\u4ef6\u6743\u9650\u4e3a655\uff0c\u5e76\u5411\u5176\u8ffd\u52a0\u5185\u5bb9beijing ,\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"341\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/4-3.png\" alt=\"\" class=\"wp-image-7670\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/4-3.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/4-3-300x144.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/4-3-600x288.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6587\u4ef6\u5185\u5bb9\u548c\u6743\u9650\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"125\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/5-3.png\" alt=\"\" class=\"wp-image-7672\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/5-3.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/5-3-300x53.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/5-3-600x106.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1aos.Open()\u51fd\u6570\u53ea\u80fd\u7528\u6765\u8bfb\u53d6\u6587\u4ef6\uff0cos.OpenFile()\u51fd\u6570\u53ef\u4ee5\u8bfb\u53d6\u4e5f\u80fd\u4ee5\u8bfb\u5199\u65b9\u5f0f\u6253\u5f00\u6587\u4ef6\uff0c\u529f\u80fd\u66f4\u5f3a\u5927\u4e00\u4e9b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">3<strong>\u3001\u590d\u5236\u6587\u4ef6<\/strong><\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ea\u9700\u7ed3\u5408\u4f7f\u7528OS \u5305\u4e2d\u7684\u51e0\u4e2a\u51fd\u6570\u3002\u4ee5\u7f16\u7a0b\u65b9\u5f0f\u590d\u5236\u6587\u4ef6\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6253\u5f00\u8981\u590d\u5236\u7684\u6587\u4ef6<\/li>\n\n\n\n<li>\u8bfb\u53d6\u5176\u5185\u5bb9<\/li>\n\n\n\n<li>\u521b\u5efa\u4e95\u6253\u5f00\u8981\u5c06\u8fd9\u4e9b\u5185\u5bb9\u590d\u5236\u5230\u5176\u4e2d\u7684\u6587\u4ef6<\/li>\n\n\n\n<li>\u5c06\u5185\u5bb9\u5199\u5165\u8fd9\u4e2a\u6587\u4ef6<\/li>\n\n\n\n<li>\u5173\u95ed\u6240\u6709\u5df1\u6253\u5f00\u7684\u6587\u4ef6<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u4e2d\u8868\u793a\u8bfb\u53d6\u4e00\u4e2a\u73b0\u6709\u6587\u4ef6cc.txt\u7684\u5185\u5bb9\uff0c\u5e76\u5c06\u5176\u590d\u5236\u5230bb.txt\u8fd9\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"706\" height=\"528\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/3-9.png\" alt=\"\" class=\"wp-image-7276\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/3-9.png 706w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/3-9-300x224.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/3-9-600x449.png 600w\" sizes=\"auto, (max-width: 706px) 100vw, 706px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u540e\u53ef\u4ee5\u770b\u5230bb.txt\u4e2d\u5df2\u7ecf\u590d\u5236\u8fc7\u6765\u4e86\u5185\u5bb9\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"304\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/4-9.png\" alt=\"\" class=\"wp-image-7278\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/4-9.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/4-9-300x129.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/4-9-600x258.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7b2c11\u884c\uff1a\u4f7f\u7528OS \u5305\u4e2d\u7684\u51fd\u6570Open \u6765\u8bfb\u53d6\u78c1\u76d8\u6587\u4ef6<\/li>\n\n\n\n<li>\u7b2c15\u884c\uff1a\u4f7f\u7528defer \u8bed\u53e5\u5728\u7a0b\u5e8f\u5b8c\u6210\u5176\u4ed6\u6240\u6709\u64cd\u4f5c\u540e\u5173\u95ed\u6587\u4ef6<\/li>\n\n\n\n<li>\u7b2c16\u884c\uff1a\u4f7f\u7528\u51fd\u6570OpenFile\u6253\u5f00\u6587\u4ef6\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8981\u6253\u5f00\u7684\u6587\u4ef6(\u4e0d\u5b58\u5728\u4f1a\u521b\u5efa)\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u7528\u4e8e\u6587\u4ef6\u7684\u6807\u5fd7\uff0c\u5728\u8fd9\u91cc\u6307\u5b9a\u7684\u662f\u8bfb\u5199\u6587\u4ef6\uff0c \u5e76\u5728\u6587\u4ef6\u4e0d\u5b58\u5728\u65f6\u521b\u5efa\u5b83\uff1b \u6700\u540e\u4e00\u4e2a\u53c2\u6570\u8bbe\u7f6e\u6587\u4ef6\u7684\u6743\u9650<\/li>\n\n\n\n<li>\u7b2c21\u884c\uff1a\u4f7f\u7528io \u5305\u4e2d\u7684\u51fd\u6570Copy \u590d\u5236\u6e90\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u5e76\u5c06\u5176\u5199\u5165\u76ee\u6807\u6587\u4ef6<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">4<strong>\u3001\u5220\u9664\u6587\u4ef6<\/strong><\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">OS \u5305\u63d0\u4f9b\u4e86\u51fd\u6570Remove\uff0c\u4f7f\u7528\u8fd9\u4e2a\u51fd\u6570\u65f6\uff0c \u4e0d\u4f1a\u53d1\u51fa\u8b66\u544a\uff0c \u4e5f\u65e0\u6cd5\u5c06\u5220\u9664\u7684\u6587\u4ef6\u6062\u590d\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"703\" height=\"264\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/5-9.png\" alt=\"\" class=\"wp-image-7285\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/5-9.png 703w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/5-9-300x113.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/5-9-600x225.png 600w\" sizes=\"auto, (max-width: 703px) 100vw, 703px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u8fd9\u6bb5\u4ee3\u7801\u540e\uff0c\u5c06\u5220\u9664test\u76ee\u5f55\u4e0b\u540d\u5b57\u4e3abb.txt\u7684\u6587\u4ef6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">5\u3001\u4f7f\u7528<code>os.Open<\/code>()\u548c<code>bufio.Reader<\/code>()\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>bufio<\/code>\u5305\u5b9e\u73b0\u4e86\u7f13\u5b58IO,\u5b83\u672c\u8eab\u5305\u88c5\u4e86<code>io.Reader<\/code>\u548c<code>io.Writer<\/code>\u5bf9\u8c61\uff0c\u521b\u5efa\u4e86\u53e6\u5916\u7684Reader\u548cWriter\u5bf9\u8c61\uff0c\u8be5\u79cd\u65b9\u5f0f\u662f\u5e26\u6709\u7f13\u5b58\u7684\uff0c\u5bf9\u4e8e\u6587\u672cI\/O\u6765\u8bf4\uff0c\u8be5\u5305\u4f7f\u7528\u8d77\u6765\u66f4\u52a0\u4fbf\u5229<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>bufio<\/code>\u6a21\u5757\u5185\u90e8\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7528\u6765\u7f13\u51b2io.Reader\u5bf9\u8c61\u7684\u7ed3\u6784\u4f53\uff0c\u540c\u65f6\u8be5\u7ed3\u6784\u4f53\u62e5\u6709\u4ee5\u4e0b\u76f8\u5173\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(1)\u3001NewReader\u51fd\u6570\u7528\u6765\u8fd4\u56de\u4e00\u4e2a\u9ed8\u8ba4\u5927\u5c0fbuffer\u7684Reader\u5bf9\u8c61\uff0c\u7b49\u540c\u4e8eNewReaderSize(rd,4096)\uff0c\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func NewReader(rd io.Reader) *Reader<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u8868\u793a\u901a\u8fc7NewReader\u51fd\u6570\u6765\u83b7\u53d6\u7f13\u51b2\u5668\uff0c\u5e76\u901a\u8fc7Read()\u51fd\u6570\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"400\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/6-3.png\" alt=\"\" class=\"wp-image-7684\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/6-3.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/6-3-300x170.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/6-3-600x339.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"76\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/7-4.png\" alt=\"\" class=\"wp-image-7686\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/7-4.png 708w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/7-4-300x32.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/7-4-600x64.png 600w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(2)\u3001NewReaderSize()\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u6307\u5b9a\u5927\u5c0fbuffer(size\u6700\u5c0f\u4e3a16)\u7684Reader\u5bf9\u8c61\uff0c\u5982\u679c io.Reader\u53c2\u6570\u5df2\u7ecf\u662f\u4e00\u4e2a\u8db3\u591f\u5927\u7684Reader\uff0c\u5b83\u5c06\u8fd4\u56de\u8be5Reader<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func NewReaderSize(rd io.Reader, size int) *Reader<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(3)\u3001Buffered()\u65b9\u6cd5\u8fd4\u56de\u4ece\u5f53\u524dbuffer\u4e2d\u80fd\u88ab\u8bfb\u5230\u7684\u5b57\u8282\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (b *Reader) Buffered() int<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(4)\u3001Discard()\u65b9\u6cd5\u8df3\u8fc7\u540e\u7eed\u7684 n \u4e2a\u5b57\u8282\u7684\u6570\u636e\uff0c\u8fd4\u56de\u8df3\u8fc7\u7684\u5b57\u8282\u6570\u3002\u5982\u679c0 &lt;= n &lt;= b.Buffered(),\u8be5\u65b9\u6cd5\u5c06\u4e0d\u4f1a\u4eceio.Reader\u4e2d\u6210\u529f\u8bfb\u53d6\u6570\u636e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (b *Reader) Discard(n int) (discarded int, err error)<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(5)\u3001Peekf\u65b9\u6cd5\u8fd4\u56de\u7f13\u5b58\u7684\u4e00\u4e2a\u5207\u7247\uff0c\u8be5\u5207\u7247\u53ea\u5305\u542b\u7f13\u5b58\u4e2d\u7684\u524dn\u4e2a\u5b57\u8282\u7684\u6570\u636e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (b *Reader) Peek(n int) (&#91;]byte, error)<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(6)\u3001Read\u65b9\u6cd5\u628aReader\u7f13\u5b58\u5bf9\u8c61\u4e2d\u7684\u6570\u636e\u8bfb\u5165\u5230[]byte\u7c7b\u578b\u7684p\u4e2d\uff0c\u5e76\u8fd4\u56de\u8bfb\u53d6\u7684\u5b57\u8282\u6570\u3002\u8bfb\u53d6\u6210\u529f\uff0cerr\u5c06\u8fd4\u56de\u7a7a\u503c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (b *Reader) Read(p &#91;]byte) (n int, err error)<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(7)\u3001ReadByte\u65b9\u6cd5\u8fd4\u56de\u5355\u4e2a\u5b57\u8282\uff0c\u5982\u679c\u6ca1\u6709\u6570\u636e\u8fd4\u56deerr<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (b *Reader) ReadByte() (byte, error)<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(8)\u3001ReadBytes\u65b9\u6cd5\u8fd4\u56de\u6570\u636e\u7684\u62f7\u8d1d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (b *Reader) ReadBytes(delim byte) (&#91;]byte, error)<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(9)\u3001ReadString\u529f\u80fd\u540cReadBytes,\u8fd4\u56de\u5b57\u7b26\u4e32<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (b *Reader) ReadString(delim byte) (string, error)<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(10)\u3001ReadRune\u65b9\u6cd5\u8bfb\u53d6\u5355\u4e2aUTF-8\u5b57\u7b26\u5e76\u8fd4\u56de\u4e00\u4e2arune\u548c\u5b57\u8282\u5927\u5c0f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (b *Reader) ReadRune() (r rune, size int, err error)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">(11)\u3001ReadLine()\u65b9\u6cd5\u7528\u4e8e\u4eceReader\u4e2d\u8bfb\u53d6\u4e00\u884c\u5185\u5bb9\uff0c\u5982\u679c\u6570\u636e\u6570\u636e\u8fc7\u957f\u800c\u65e0\u6cd5\u5b8c\u5168\u653e\u5165\u7f13\u51b2\u533a\u4e2d\uff0c\u4f1a\u5c06isPrefix\u8bbe\u7f6e\u4e3atrue\uff0c\u6b64\u65b9\u6cd5\u5df2\u8fc7\u65f6\uff0c\u4e0d\u63a8\u8350\u4f7f\u7528\u4e86\uff0c\u63a8\u8350\u4f7f\u7528ReadBytes\u548cReadString<\/mark><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (b *Reader) ReadLine() (line &#91;]byte, isPrefix bool, err error)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">6\u3001\u901a\u8fc7os.ReadDir()\u8bfb\u53d6\u76ee\u5f55\u5185\u5bb9<\/mark><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"714\" height=\"654\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/05\/7-3.png\" alt=\"\" class=\"wp-image-13462\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/05\/7-3.png 714w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/05\/7-3-300x275.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/05\/7-3-600x550.png 600w\" sizes=\"auto, (max-width: 714px) 100vw, 714px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>7\u3001\u4f7f\u7528bufio\u5305\u7684Scanner\u5bf9\u6570\u636e\u8fdb\u884c\u8bfb\u53d6(\u63a8\u8350)&#8212;\u9010\u884c\u8bfb\u53d6<\/strong><\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u66f4\u63a8\u8350\u4f7f\u7528Scanner\u65b9\u6cd5\u5bf9\u6570\u636e\u8fdb\u884c\u8bfb\u53d6\uff0c\u800c\u975e\u76f4\u63a5\u4f7f\u7528Reader\u7c7b\u3002Scanner\u53ef\u4ee5\u901a\u8fc7splitFunc\u5c06\u8f93\u5165\u6570\u636e\u62c6\u5206\u4e3a\u591a\u4e2atoken\uff0c\u7136\u540e\u4f9d\u6b21\u8fdb\u884c\u8bfb\u53d6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u548cReader\u7c7b\u4f3c\uff0cScanner\u9700\u8981\u7ed1\u5b9a\u5230\u67d0\u4e2aio.Reader\u4e0a\uff0c\u901a\u8fc7NewScannner\u8fdb\u884c\u521b\u5efa\uff0c\u51fd\u6570\u58f0\u660e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func NewScanner(r io.Reader) *Scanner<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4f7f\u7528\u4e4b\u524d\u8fd8\u9700\u8981\u8bbe\u7f6esplitFunc\uff08\u9ed8\u8ba4\u4e3aScanLines\uff09\uff0csplitFunc\u7528\u4e8e\u5c06\u8f93\u5165\u6570\u636e\u62c6\u5206\u4e3a\u591a\u4e2atoken\u3002bufio\u6a21\u5757\u63d0\u4f9b\u4e86\u51e0\u4e2a\u9ed8\u8ba4splitFunc\uff0c\u80fd\u591f\u6ee1\u8db3\u5927\u90e8\u5206\u573a\u666f\u7684\u9700\u6c42\uff0c\u6839\u636e\u5b9e\u9645\u4e1a\u52a1\u9700\u6c42\u8fdb\u884c\u9009\u62e9\uff0c\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ScanBytes\uff0c\u6309\u7167byte\u8fdb\u884c\u62c6\u5206<\/li>\n\n\n\n<li>ScanLines\uff0c\u6309\u7167\u884c(\u201c\\n\u201d)\u8fdb\u884c\u62c6\u5206<\/li>\n\n\n\n<li>ScanRunes\uff0c\u6309\u7167utf-8\u5b57\u7b26\u8fdb\u884c\u62c6\u5206<\/li>\n\n\n\n<li>ScanWords\uff0c\u6309\u7167\u5355\u8bcd(\u201d \u201c)\u8fdb\u884c\u62c6\u5206<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7Scanner\u7684Split\u65b9\u6cd5\uff0c\u53ef\u4ee5\u4e3aScanner\u6307\u5b9asplitFunc\u3002\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scanner := bufio.NewScanner(os.StdIn)\nscanner.Split(bufio.ScanWords\uff09<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Scanner\u521d\u59cb\u5316\u4e4b\u540e\uff0c\u901a\u8fc7Scan\u65b9\u6cd5\u8bfb\u53d6\u6570\u636e\uff0c\u4f7f\u7528Text\u548cBytes\u65b9\u6cd5\u83b7\u53d6\u6570\u636e\uff0cText\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0cBytes\u8fd4\u56de\u5b57\u8282\u6570\u7ec4\u3002\u65b9\u6cd5\u58f0\u660e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (s *Scanner) Scan() bool        \/\/\u8bfb\u53d6\u6570\u636e\nfunc (s *Scanner) Text() string      \/\/\u83b7\u53d6\u6570\u636e\uff0c\u8fd4\u56de\u5b57\u7b26\u4e32\nfunc (s *Scanner) Bytes() &#91;]byte      \/\/\u83b7\u53d6\u6570\u636e\uff0c\u8fd4\u56de\u5b57\u8282\u6570\u7ec4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u8868\u793a\u901a\u8fc7NewScanner()\u65b9\u6cd5\u5e76\u4ee5\u9ed8\u8ba4\u7684ScanLines\u8bfb\u53d6\u6570\u636e\uff0c\u5e76\u4ee5\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u8f93\u51fa\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"315\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/8-4.png\" alt=\"\" class=\"wp-image-7722\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/8-4.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/8-4-300x134.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/8-4-600x267.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"145\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/9-3.png\" alt=\"\" class=\"wp-image-7724\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/9-3.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/9-3-300x61.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/9-3-600x123.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">8\u3001\u901a\u8fc7io\u5305\u4e2d\u7684\u76f8\u5173\u51fd\u6570\u5199\u5165\u6587\u4ef6\uff1a<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728<code>io<\/code>\u5305\u4e2d\u6709\u4e00\u4e2a<code>WriteString()<\/code>\u51fd\u6570\uff0c\u7528\u6765\u5c06\u5b57\u7b26\u4e32\u5199\u5165\u4e00\u4e2a<code>Writer<\/code>\u5bf9\u8c61\u4e2d\uff0c\u51fd\u6570\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5c06\u5b57\u7b26\u4e32s\u5199\u5165w(\u53ef\u4ee5\u662f\u4e00\u4e2a&#91;]byte)\uff0c\u5982\u679cw\u5b9e\u73b0\u4e86\u4e00\u4e2aWriteString\u65b9\u6cd5\uff0c\u5b83\u53ef\u4ee5\u88ab\u76f4\u63a5\u8c03\u7528\u3002\u5426\u5219w.Write\u4f1a\u518d\u4e00\u6b21\u88ab\u8c03\u7528\nfunc WriteString(w Writer, s string) (n int, err error)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u8868\u793a\u901a\u8fc7 <code>WriteString()<\/code>\u51fd\u6570 \u5c06\u5b57\u7b26\u4e32w\u7684\u5185\u5bb9\u5199\u5165\u5230\u6587\u4ef6\u4e2d\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"321\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/10-3.png\" alt=\"\" class=\"wp-image-7729\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/10-3.png 708w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/10-3-300x136.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/10-3-600x272.png 600w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>9\u3001\u4f7f\u7528<code>bufio<\/code>\u5305\u4e2d\u7684\u76f8\u5173\u51fd\u6570\u5199\u5165\u6587\u4ef6\uff1a<\/strong><\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>bufio<\/code>\u548c<code>io<\/code>\u5305\u4e2d\u5f88\u591a\u64cd\u4f5c\u90fd\u662f\u76f8\u4f3c\u7684\uff0c\u552f\u4e00\u4e0d\u540c\u7684\u5730\u65b9\u662f<code>bufio<\/code>\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7f13\u51b2\u7684\u64cd\u4f5c\uff0c\u5982\u679c\u5bf9\u6587\u4ef6I\/O\u64cd\u4f5c\u6bd4\u8f83\u9891\u7e41\u7684\uff0c\u4f7f\u7528<code>bufio<\/code>\u8fd8\u662f\u80fd\u589e\u52a0\u4e00\u4e9b\u6027\u80fd\u7684<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728<code>bufio<\/code>\u5305\u4e2d\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a<code>Writer<\/code>\u7a7a\u7ed3\u6784\u4f53\uff0c\u4e00\u822c\u9700\u8981\u4f7f\u7528NewWriter\u6216\u8005NewWriterSize\u6765\u521d\u59cb\u5316\u4e00\u4e2a\u7ed3\u6784\u4f53\u5bf9\u8c61\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(1)\u3001NewWriter\u65b9\u6cd5\u8fd4\u56de\u9ed8\u8ba4\u7f13\u51b2\u5927\u5c0f\u7684Writer\u5bf9\u8c61(\u9ed8\u8ba4\u662f4096)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func NewWriter(w io.Writer) *Writer    \/\/\u521b\u5efa\u5199\u5165\u5bf9\u8c61,\u5b9e\u9645\u4e5f\u662f\u8c03\u7528\u7684NewWriterSize<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">(2)\u3001NewWriterSize\u6307\u5b9a\u7f13\u51b2\u5927\u5c0f\u521b\u5efa\u4e00\u4e2aWriter\u5bf9\u8c61<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func NewWriterSize(w io.Writer, size int) *Writer    \/\/\u521b\u5efa\u5199\u5165\u5bf9\u8c61<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Writer\u5bf9\u8c61\u76f8\u5173\u7684\u5199\u5165\u6570\u636e\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u628ap\u4e2d\u7684\u5185\u5bb9\u5199\u5165buffer,\u8fd4\u56de\u5199\u5165\u7684\u5b57\u8282\u6570\u548c\u9519\u8bef\u4fe1\u606f\u3002\u5982\u679cnn&lt;len(p),\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\u4e2d\u4f1a\u5305\u542b\u4e3a\u4ec0\u4e48\u5199\u5165\u7684\u6570\u636e\u6bd4\u8f83\u77ed\nfunc (b *Writer) Write(p &#91;]byte) (nn int, err error)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5c06buffer\u4e2d\u7684\u6570\u636e\u5199\u5165 io.Writer\nfunc (b *Writer) Flush() error<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u4e09\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u76f4\u63a5\u5199\u5165\u5230\u6587\u4ef6\u4e2d\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5199\u5165\u5355\u4e2a\u5b57\u8282\nfunc (b *Writer) WriteByte(c byte) error<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5199\u5165\u5355\u4e2aUnicode\u6307\u9488\u8fd4\u56de\u5199\u5165\u5b57\u8282\u6570\u9519\u8bef\u4fe1\u606f\nfunc (b *Writer) WriteRune(r rune) (size int, err error)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5199\u5165\u5b57\u7b26\u4e32\u5e76\u8fd4\u56de\u5199\u5165\u5b57\u8282\u6570\u548c\u9519\u8bef\u4fe1\u606f\nfunc (b *Writer) WriteString(s string) (int, error)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u8868\u793a\u4f7f\u7528Writer\u5bf9\u8c61\u7684\u65b9\u6cd5\u8fdb\u884c\u5199\u5165\u6570\u636e\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"434\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/11-2.png\" alt=\"\" class=\"wp-image-7736\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/11-2.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/11-2-300x184.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/11-2-600x367.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u8868\u793a\u901a\u8fc7WriteString()\u5c06\u5b57\u7b26\u4e32\u5199\u5165\u5230\u6587\u4ef6\u4e2d\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"513\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-4.jpg\" alt=\"\" class=\"wp-image-16739\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-4.jpg 692w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-4-300x222.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-4-600x445.jpg 600w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"691\" height=\"68\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-4.jpg\" alt=\"\" class=\"wp-image-16740\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-4.jpg 691w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-4-300x30.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-4-600x59.jpg 600w\" sizes=\"auto, (max-width: 691px) 100vw, 691px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a\u4f7f\u7528bufio\u5728\u5199\u5165\u5230\u5185\u5b58\u7684\u7f13\u51b2\u533a\u540e\uff0c\u9700\u8981\u901a\u8fc7Flush()\u5c06\u5185\u5bb9\u5237\u65b0\u5230\u786c\u76d8\u4e2d\uff0c\u5426\u5219\u6587\u4ef6\u4e2d\u6ca1\u6709\u6570\u636e<\/p>\n\n\n\n<p class=\"has-text-align-center has-normal-font-size wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u4e09\u3001\u4f7f\u7528\u6587\u4ef6\u6765\u7ba1\u7406\u914d\u7f6e<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u7f16\u7a0b\u4e2d\u5e38\u4f7f\u7528\u6587\u4ef6\u6765\u7ba1\u7406\u914d\u7f6e\u3002\u8003\u8651\u5230\u4ee3\u7801\u53ef\u80fd\u5728\u4e0d\u540c\u7684\u73af\u5883\u4e2d\u6267\u884c\uff0c\u53ef\u4f7f\u7528\u4e00\u4e2a\u6587\u4ef6\u6765\u8bbe\u7f6e\u5404\u79cd\u7528\u4e8e\u542f\u52a8\u7a0b\u5e8f\u7684\u914d\u7f6e\u53c2\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5e94\u7528\u7a0b\u5e8f\u5c06\u4ece\u5f00\u53d1\u73af\u5883\u79fb\u5230\u751f\u6210\u73af\u5883\u4e2d\uff0c\u800c\u4f7f\u7528\u6587\u4ef6\u662f\u7ba1\u7406\u73af\u5883\u5dee\u5f02\u7684\u6709\u6548\u65b9\u5f0f\u3002\u8fd9\u79cd\u73af\u5883\u5dee\u522b\u5305\u62ec\u5982\u4e0b\u51e0\u4e2a\u65b9\u9762:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Web \u670d\u52a1\u7684URL<\/li>\n\n\n\n<li>\u8bbf\u95ee\u5bc6\u94a5<\/li>\n\n\n\n<li>\u73af\u5883\u53d8\u91cf<\/li>\n\n\n\n<li>\u7aef\u53e3\u53f7<\/li>\n<\/ul>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\">\u4f7f<strong>\u7528JSON \u6587\u4ef6<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u58f0\u660e\u53ef\u5b58\u50a8\u5728\u6587\u4ef6\u4e2d\u5e76\u5728\u5fc5\u8981\u65f6\u8bfb\u53d6\u7684\u914d\u7f6e\u65b9\u9762\uff0cJSON \u662f\u4e00\u79cd\u5353\u6709\u6210\u6548\u7684\u6807\u51c6\u65b9\u5f0f\u3002\u5c06\u914d\u7f6e\u5b58\u50a8\u5728\u6587\u4ef6\u4e2d\u7684\u53e6\u4e00\u4e2a\u4f18\u70b9\u662f\uff0c\u53ef\u5bf9\u5176\u8fdb\u884c\u7248\u672c\u63a7\u5236\u4e95\u96c6\u6210\u5230\u81ea\u52a8\u6784\u5efa\u8fc7\u7a0b\u4e2d\uff0cJSON \u662f\u4e00\u79cd\u58f0\u660e\u952e\u503c\u7684\u7b80\u5355\u65b9\u5f0f\uff0c\u60a8\u53ef\u5c06\u8fd9\u4e9b\u952e\u503c\u89e3\u7801\u4e3aGo \u7ed3\u6784\u4f53\uff0c\u518d\u4f7f\u7528\u5b83\u4eec<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u5728test\u76ee\u5f55\u4e2d\u5b9a\u4e49json\u6587\u4ef6config.json\uff0c\u6dfb\u52a0\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"332\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/6-9.png\" alt=\"\" class=\"wp-image-7291\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/6-9.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/6-9-300x141.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/6-9-600x282.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7ioutil.Readfile\u51fd\u6570\u8bfb\u53d6json\uff0c\u5e76\u5c06\u5176\u89e3\u7801\u4e3a\u4e00\u4e2a\u914d\u7f6e\u7ed3\u6784\u4f53\uff0c\u4f5c\u4e3a\u914d\u7f6e\u6570\u636e\u4f7f\u7528\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"570\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/7-9.png\" alt=\"\" class=\"wp-image-7293\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/7-9.png 708w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/7-9-300x242.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/7-9-600x483.png 600w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"95\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/8-8.png\" alt=\"\" class=\"wp-image-7294\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/8-8.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/8-8-300x40.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/8-8-600x80.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7b2c17\u884c\uff1aioutil.ReadFile\u8bfb\u53d6\u6587\u4ef6\u540e\u8fd4\u56de\u7c7b\u578b\u4e3a\u5207\u7247\u7c7b\u578b<\/li>\n\n\n\n<li>\u7b2c22\u884c\uff1a\u901a\u8fc7json.Unmarshal\u5c06json\u6570\u636e\u89e3\u7801\u5230\u7ed3\u6784\u4f53\u4e2d\uff0c\u89e3\u7801\u5230\u7684\u7ed3\u6784\u4f53\u5fc5\u987b\u662f\u6307\u9488<\/li>\n<\/ul>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a<em>Json.Unmarshal\u662f\u5c06json\u5b57\u7b26\u4e32\u89e3\u7801\u5230\u76f8\u5e94\u7684\u6570\u636e\u7ed3\u6784\u4e2d\u3002 json\u5b57\u7b26\u4e32\u89e3\u6790\u65f6\uff0c\u9700\u8981\u4e00\u4e2a&#8221;\u63a5\u6536\u4f53&#8221;\u63a5\u6536\u89e3\u6790\u540e\u7684\u6570\u636e\uff0c\u5e76\u4e14\u8fd9\u4e2a\u63a5\u6536\u4f53\u5fc5\u987b\u662f\u4f20\u9012\u6307\u9488\uff08\u4f8b\u5982\uff1a&amp;productresult\uff09\uff0c\u5426\u5219\u89e3\u6790\u867d\u7136\u4e0d\u62a5\u9519\uff0c\u4f46\u6570\u636e\u65e0\u6cd5\u8d4b\u503c\u5230\u63a5\u6536\u4f53\u4e2d<\/em><\/p>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color wp-block-paragraph\"><strong>\u4f7f\u7528TOML \u6587\u4ef6<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">TOML ( Tom \u2019s Obvious, Minimal Language \uff09\u662f\u4e00\u79cd\u4e13\u4e3a\u5b58\u50a8\u914d\u7f6e\u6587\u4ef6\u800c\u8bbe\u8ba1\u7684\u683c\u5f0f\uff0c\u76f8\u6bd4\u4e8eJSON \uff0c\u5176\u8868\u8fbe\u80fd\u529b\u66f4\u5f3a\uff0c\u4e14\u66f4\u5bb9\u6613\u6620\u5c04Go \u7c7b\u578b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">TOML\u683c\u5f0f\u975e\u5e38\u7075\u6d3b\uff0c\u53ef\u4ee5\u662f\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u3001\u5e03\u5c14\u7b49\u7b80\u5355\u7c7b\u578b\uff0c\u4e5f\u53ef\u4ee5\u662f\u6570\u7ec4\u3001map\u7b49\u7b49\u590d\u6742\u7684\u7c7b\u578b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JSON \u662f\u4e3a\u5e8f\u5217\u5316\u6570\u636e\u800c\u8bbe\u8ba1\u7684\uff0c\u800cTOML \u662f\u4e13\u95e8\u4e3a\u5b58\u50a8\u914d\u7f6e\u6587\u4ef6\u800c\u8bbe\u8ba1\u7684\uff0c\u56e0\u6b64TOML \u76f8\u6bd4\u4e8eJSON\u6709\u4e00\u5b9a\u7684\u4f18\u52bf\uff0c\u5982\u66f4\u5bb9\u6613\u9605\u8bfb\u3001\u5177\u5907JSON \u6ca1\u6709\u7684\u7279\u6027\uff08\u5982\u6ce8\u91ca\uff09\uff0c\u5728\u57fa\u672c\u5c42\u9762\uff0c TOML\u7684\u8bed\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u53ef\u50cfJSON \u90a3\u6837\u6307\u5b9a\u952e\u548c\u503c\uff0cconfig.toml\u5185\u5bb9 \u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>name = \"zhangsan\"\nage = 100\nweight = \"100kg\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0eJSON \u4e00\u6837\uff0c TOML \u4e5f\u4e0d\u662fGo \u7684\u7ec4\u6210\u90e8\u5206\uff0c\u5b83\u53ef\u7528\u4e8e\u4efb\u4f55\u8bed\u8a00\u3002Go \u6807\u51c6\u5e93\u4e2d\u6ca1\u6709\u652f\u6301TOML \u7684\u5305\uff0c\u867d\u7136\u60a8\u53ef\u7f16\u5199\u4e00\u4e9b\u4ee3\u7801\u6765\u5206\u6790TOML\u6587\u4ef6\uff0c\u4f46\u6709\u4e00\u4e9b\u5353\u8d8a\u7684\u7b2c\u4e09\u65b9TOML\u5305\u4e5f\u53ef\u4ee5\u4f7f\u7528\uff0c\u6700\u6d41\u884c\u7684TOML\u5305\u4e4b\u4e00\u662fBurntSushi \u7f16\u5199\u7684\u3002\u8fd9\u4e2a\u5305\u80fd\u591f\u8ba9\u60a8\u8f7b\u677e\u5730\u5728Go \u8bed\u8a00\u4e2d\u5c06TOML\u7528\u4f5c\u914d\u7f6e\u6587\u4ef6\u683c\u5f0f\uff0c\u4f46\u7531\u4e8e\u5b83\u5e76\u4e0d\u5305\u542b\u5728\u6807\u51c6\u5e93\u4e2d\uff0c\u56e0\u6b64\u60a8\u5fc5\u987b\u5355\u72ec\u5b89\u88c5\uff0c\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go get github.com\/BurntSushi\/toml<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b89\u88c5\u540e\u5728GOPATH\u7684src\u76ee\u5f55\u4e0b\u53ef\u4ee5\u770b\u5230\u5b89\u88c5\u4e4b\u540e\u7684\u5305\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"706\" height=\"198\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/9-6.png\" alt=\"\" class=\"wp-image-7300\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/9-6.png 706w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/9-6-300x84.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/9-6-600x168.png 600w\" sizes=\"auto, (max-width: 706px) 100vw, 706px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">TOML\u5305\u63d0\u4f9b\u4e86\u51fd\u6570DecodeFile \uff0c\u8fd9\u4e2a\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u6587\u4ef6\u540d\u4ee5\u53ca\u4e00\u4e2a\u8981\u5c06TOML \u89e3\u7801\u5230\u5176\u4e2d\u7684\u7ed3\u6784\u4f53<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u4f7f\u5176\u4ecetoml\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u7136\u540e\u89e3\u7801\u5230\u7ed3\u6784\u4f53\u4e2d\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"488\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/10-6.png\" alt=\"\" class=\"wp-image-7302\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/10-6.png 708w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/10-6-300x207.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/10-6-600x414.png 600w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"78\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/11-5.png\" alt=\"\" class=\"wp-image-7305\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/11-5.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/11-5-300x33.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/02\/11-5-600x66.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7b2c18\u884c\uff1atoml.DecodeFile\u8fd4\u56de\u7684\u503c\u7c7b\u578b\u4e3atoml.MetaData\uff0c\u5e76\u4e0d\u9700\u8981\u56e0\u6b64\u5c06\u63a5\u6536\u503c\u8bbe\u7f6e\u4e3a\u533f\u540d\u53d8\u91cf&#8221;_&#8221;<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u4f7f\u7528ioutil \u5305\u8bfb\u5199\u6587\u4ef6 \u9274\u4e8e\u5904\u7406\u6587\u4ef6\u662f\u4e00\u79cd\u5f88\u5e38\u89c1\u7684\u4efb\u52a1\uff0c\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86ioutil \u5305\uff0c\u8ba9\u60a8\u80fd\u591f\u5feb\u901f\u6267 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":7237,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111,23],"tags":[],"class_list":["post-7235","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go","category-rong"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/7235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=7235"}],"version-history":[{"count":127,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/7235\/revisions"}],"predecessor-version":[{"id":16742,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/7235\/revisions\/16742"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/7237"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=7235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=7235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=7235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}