{"id":863,"date":"2024-11-07T13:32:32","date_gmt":"2024-11-07T05:32:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/863\/"},"modified":"2024-11-07T13:32:32","modified_gmt":"2024-11-07T05:32:32","slug":"%e4%bd%bf%e7%94%a8%e8%87%aa%e5%ae%9a%e4%b9%89%e7%bb%93%e6%9e%84%e4%bd%93%e4%bd%9c%e4%b8%ba%e9%94%99%e8%af%af%e7%b1%bb%e5%9e%8b%e6%97%b6%ef%bc%8c%e5%a6%82%e4%bd%95%e8%ae%a9-echo-%e6%a1%86%e6%9e%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/863\/","title":{"rendered":"\u4f7f\u7528\u81ea\u5b9a\u4e49\u7ed3\u6784\u4f53\u4f5c\u4e3a\u9519\u8bef\u7c7b\u578b\u65f6\uff0c\u5982\u4f55\u8ba9 Echo \u6846\u67b6\u6b63\u786e\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\uff1f"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1050\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173019094799519.jpg\" width=\"800\" height=\"320\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173019094799519.jpg 800w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173019094799519-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173019094799519-768x307.jpg 768w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173019094799519-670x268.jpg 670w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" title=\"\u4f7f\u7528\u81ea\u5b9a\u4e49\u7ed3\u6784\u4f53\u4f5c\u4e3a\u9519\u8bef\u7c7b\u578b\u65f6\uff0c\u5982\u4f55\u8ba9 Echo \u6846\u67b6\u6b63\u786e\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\uff1f\u63d2\u56fe\" alt=\"\u4f7f\u7528\u81ea\u5b9a\u4e49\u7ed3\u6784\u4f53\u4f5c\u4e3a\u9519\u8bef\u7c7b\u578b\u65f6\uff0c\u5982\u4f55\u8ba9 Echo \u6846\u67b6\u6b63\u786e\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>go \u5173\u4e8e\u7ed3\u6784\u4f53\u4f7f\u7528\u7684\u95ee\u9898<\/strong><\/p>\n<p>\u4f60\u4f7f\u7528\u81ea\u5df1\u7684\u7ed3\u6784\u4f53 test1 \u540e\u9047\u5230\u7684\u9519\u8bef\u662f\uff1atest1 \u6ca1\u6709\u5b9e\u73b0 error() \u65b9\u6cd5\uff0c\u4ece\u800c\u4e0d\u7b26\u5408 error \u63a5\u53e3\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u5728 test1 \u7ed3\u6784\u4f53\u4e2d\u5b9e\u73b0 error() \u65b9\u6cd5\uff1a<\/p>\n<pre>func (t *test1) error() string {\n    \/\/ \u81ea\u5b9a\u4e49\u9519\u8bef\u4fe1\u606f\n    return fmt.sprintf(\"code %d: %s\", t.code, t.message)\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u89e3\u91ca\uff1a<\/strong><\/p>\n<p>error \u63a5\u53e3\u662f\u4e00\u4e2a\u5185\u7f6e\u7684 go \u63a5\u53e3\uff0c\u5176\u5b9a\u4e49\u4e86\u4e00\u4e2a error() \u65b9\u6cd5\u3002\u5f53\u4efb\u4f55\u7c7b\u578b\u5b9e\u73b0 error \u63a5\u53e3\u65f6\uff0c\u5b83\u53ef\u4ee5\u88ab\u7528\u4f5c error \u7c7b\u578b\u3002\u901a\u8fc7\u5b9e\u73b0 error() \u65b9\u6cd5\uff0ctest1 \u7ed3\u6784\u4f53\u7b26\u5408 error \u63a5\u53e3\uff0c\u4ece\u800c\u53ef\u4ee5\u88ab\u7528\u4f5c error \u7c7b\u578b\u8fd4\u56de\u3002<\/p>\n<p><strong>\u5173\u4e8e\u7b2c\u4e8c\u4e2a\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u4f60\u4f7f\u7528\u81ea\u5df1\u7684 test1 \u7ed3\u6784\u4f53\u65f6\uff0c\u9519\u8bef\u4fe1\u606f\u65e0\u6cd5\u6b63\u786e\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\uff0c\u8fd9\u662f\u56e0\u4e3a echo \u5185\u90e8\u673a\u5236\u7684\u95ee\u9898\u3002echo \u4f7f\u7528\u4e86\u4e2d\u95f4\u4ef6 recover() \u6765\u5904\u7406\u9519\u8bef\uff0c\u5f53\u8fd4\u56de\u7684\u9519\u8bef\u5b9e\u73b0\u4e86 error \u63a5\u53e3\u65f6\uff0c\u5b83\u4f1a\u5c06\u9519\u8bef\u6d88\u606f\u5bfc\u51fa\u5230 http \u54cd\u5e94\u4e2d\u3002\u4f46\u662f\uff0c\u5982\u679c\u8fd4\u56de\u9519\u8bef\u6ca1\u6709\u5b9e\u73b0 error \u63a5\u53e3\uff0cecho \u5c06\u4f1a\u62e6\u622a\u9519\u8bef\u5e76\u5728\u5185\u90e8\u5904\u7406\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528 recover() \u4e2d\u95f4\u4ef6\u4e2d\u7684 stacksize() \u53c2\u6570\u6765\u63a7\u5236\u9519\u8bef\u5806\u6808\u7684\u622a\u65ad\u3002\u5efa\u8bae\u8bbe\u7f6e stacksize() \u53c2\u6570\u4e3a 1 \u4ee5\u907f\u514d\u9519\u8bef\u88ab\u622a\u65ad\uff1a<\/p>\n<pre>\/\/ Use Recover middleware with StackSize of 1 to avoid error truncation.\ne.Use(middleware.Recover(middleware.RecoverConfig{StackSize: 1}))<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528\u81ea\u5b9a\u4e49\u7ed3\u6784\u4f53\u4f5c\u4e3a\u9519\u8bef\u7c7b\u578b\u65f6\uff0c\u5982\u4f55\u8ba9 Echo \u6846\u67b6\u6b63\u786e\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>go \u5173\u4e8e\u7ed3\u6784\u4f53\u4f7f\u7528\u7684\u95ee\u9898 \u4f60\u4f7f\u7528\u81ea\u5df1\u7684\u7ed3\u6784\u4f53 test1 \u540e\u9047\u5230\u7684\u9519\u8bef\u662f\uff1atest1 \u6ca1\u6709\u5b9e\u73b0 error() \u65b9\u6cd5\uff0c\u4ece\u800c\u4e0d\u7b26\u5408 error \u63a5\u53e3\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u5728 test1 \u7ed3\u6784\u4f53\u4e2d\u5b9e\u73b0 error() \u65b9\u6cd5\uff1a func (t *test1) error() string { \/\/ \u81ea\u5b9a\u4e49\u9519\u8bef\u4fe1\u606f return fmt.sprintf(&#8220;code %d: %s&#8221;, t.code, t.message) } \u767b\u5f55\u540e\u590d\u5236 \u89e3\u91ca\uff1a error \u63a5\u53e3\u662f\u4e00\u4e2a\u5185\u7f6e\u7684 go \u63a5\u53e3\uff0c\u5176\u5b9a\u4e49\u4e86\u4e00\u4e2a error() \u65b9\u6cd5\u3002\u5f53\u4efb\u4f55\u7c7b\u578b\u5b9e\u73b0 error \u63a5\u53e3\u65f6\uff0c\u5b83\u53ef\u4ee5\u88ab\u7528\u4f5c error \u7c7b\u578b\u3002\u901a\u8fc7\u5b9e\u73b0 error() \u65b9\u6cd5\uff0ctest1 \u7ed3\u6784\u4f53\u7b26\u5408 error \u63a5\u53e3\uff0c\u4ece\u800c\u53ef\u4ee5\u88ab\u7528\u4f5c error \u7c7b\u578b\u8fd4\u56de\u3002 \u5173\u4e8e\u7b2c\u4e8c\u4e2a\u95ee\u9898\uff1a \u4f60\u4f7f\u7528\u81ea\u5df1\u7684 test1 \u7ed3\u6784\u4f53\u65f6\uff0c\u9519\u8bef\u4fe1\u606f\u65e0\u6cd5\u6b63\u786e\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\uff0c\u8fd9\u662f\u56e0\u4e3a echo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-863","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=863"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/863\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}