{"id":1244,"date":"2022-11-30T10:04:00","date_gmt":"2022-11-30T02:04:00","guid":{"rendered":"https:\/\/fdream.net\/blog\/?p=1244"},"modified":"2022-12-05T11:26:07","modified_gmt":"2022-12-05T03:26:07","slug":"go%e6%8c%87%e5%8d%97%e7%bb%83%e4%b9%a07-reader","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/1244","title":{"rendered":"Go\u6307\u5357\u7ec3\u4e607-Reader"},"content":{"rendered":"\n<p>\u8fd9\u4e2a\u662f<a rel=\"noreferrer noopener\" href=\"https:\/\/go.dev\/tour\/list\" target=\"_blank\">A Tour of Go<\/a>\u8fd9\u4e2a\u6559\u7a0b\u91cc\u9762\u7684\u7b2c\u4e03\u4e2a\u7ec3\u4e60\uff0c<a rel=\"noreferrer noopener\" href=\"https:\/\/tour.go-zh.org\/methods\/22\" target=\"_blank\">\u539f\u9898<\/a>\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5b9e\u73b0\u4e00\u4e2a&nbsp;<code>Reader<\/code>&nbsp;\u7c7b\u578b\uff0c\u5b83\u4ea7\u751f\u4e00\u4e2a ASCII \u5b57\u7b26&nbsp;<code>'A'<\/code>&nbsp;\u7684\u65e0\u9650\u6d41\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u539f\u9898\u4ee3\u7801\u6a21\u677f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n\t\"golang.org\/x\/tour\/reader\"\n)\n\ntype MyReader struct{}\n\n\/\/ TODO: \u7ed9 MyReader \u6dfb\u52a0\u4e00\u4e2a Read(&#91;]byte) (int, error) \u65b9\u6cd5\n\nfunc main() {\n\treader.Validate(MyReader{})\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u9898\u5176\u5b9e\u5c31\u662f\u8981\u5b9e\u73b0\u4e00\u4e2aRead\u63a5\u53e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (T) Read(b &#91;]byte) (n int, err error)<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u5728\u8fd9\u4e2a\u63a5\u53e3\u91cc\u9762\u4e00\u76f4\u8fd4\u56deb\u7684\u957f\u5ea6\uff0c\u7ed9b\u6ce8\u5165\u76f8\u5e94\u957f\u5ea6\u7684A\u7684ASCII\u7801\u5c31\u597d\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n\t\"golang.org\/x\/tour\/reader\"\n)\n\ntype MyReader struct{}\n\n\/\/ TODO: \u7ed9 MyReader \u6dfb\u52a0\u4e00\u4e2a Read(&#91;]byte) (int, error) \u65b9\u6cd5\nfunc (r MyReader) Read(b &#91;]byte) (int, error) {\n\tfor i := range b {\n\t\tb&#91;i] = 'A'\n\t}\n\treturn len(b), nil\n}\n\nfunc main() {\n\treader.Validate(MyReader{})\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e2a\u662fA Tour of Go\u8fd9\u4e2a\u6559\u7a0b\u91cc\u9762\u7684\u7b2c\u4e03\u4e2a\u7ec3\u4e60\uff0c\u539f\u9898\u5982\u4e0b\uff1a \u5b9e\u73b0\u4e00\u4e2a&nbsp;Reader&nbsp;\u7c7b\u578b\uff0c\u5b83\u4ea7\u751f\u4e00\u4e2a ASCII \u5b57\u7b26&nbsp;&#8216;A&#8217;&nbsp;\u7684\u65e0\u9650\u6d41\u3002 \u539f\u9898\u4ee3\u7801\u6a21\u677f\u5982\u4e0b\uff1a \u8fd9\u9898\u5176\u5b9e\u5c31\u662f\u8981\u5b9e\u73b0\u4e00\u4e2aRead\u63a5\u53e3\uff1a \u7136\u540e\u5728\u8fd9\u4e2a\u63a5\u53e3\u91cc\u9762\u4e00\u76f4\u8fd4\u56deb\u7684\u957f\u5ea6\uff0c\u7ed9b\u6ce8\u5165\u76f8\u5e94\u957f\u5ea6\u7684A\u7684ASCII\u7801\u5c31\u597d\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[374],"class_list":["post-1244","post","type-post","status-publish","format-standard","hentry","category-coding","tag-go"],"views":1807,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/1244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=1244"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/1244\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=1244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=1244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=1244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}