{"id":159638,"date":"2020-09-24T16:06:51","date_gmt":"2020-09-24T08:06:51","guid":{"rendered":"http:\/\/4563.org\/?p=159638"},"modified":"2020-09-24T16:06:51","modified_gmt":"2020-09-24T08:06:51","slug":"gin-%e5%90%af%e5%8a%a8%e4%b9%8b%e5%90%8e-%e8%b7%af%e7%94%b1%e5%90%8e%e9%9d%a2%e7%9a%84-handlers-%e6%95%b0%e9%87%8f%e6%98%af%e4%bb%80%e4%b9%88%e6%84%8f%e6%80%9d","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=159638","title":{"rendered":"Gin \u542f\u52a8\u4e4b\u540e, \u8def\u7531\u540e\u9762\u7684 Handlers \u6570\u91cf\u662f\u4ec0\u4e48\u610f\u601d"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Gin \u542f\u52a8\u4e4b\u540e, \u8def\u7531\u540e\u9762\u7684 Handlers \u6570\u91cf\u662f\u4ec0\u4e48\u610f\u601d               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : richzhu <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h3>Handler \u4e00\u76f4\u90fd\u662f 4<\/h3>\n<p>\u5927\u4f6c\u4eec\u597d\uff0c\u7528 Gin \u4ee5\u6765\u4e00\u76f4\u6709\u4e2a\u95ee\u9898\uff0c\u6bcf\u6b21\u7b49\u5230\u9879\u76ee\u542f\u52a8\u4e4b\u540e\uff0c\u6bcf\u4e00\u6761\u8def\u7531\u540e\u9762\u90fd\u6709\u4e00\u4e2a \uff08\u6570\u91cf Handlers \uff09\u7684\u663e\u793a\uff0c\u5e76\u4e14\u6570\u91cf\u662f 4\uff0c \u5982\u4e0b\u56fe\uff1a <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/09\/20200925_5f6d6ea5d999a.png\" alt=\"Gin \u542f\u52a8\u4e4b\u540e, \u8def\u7531\u540e\u9762\u7684 Handlers \u6570\u91cf\u662f\u4ec0\u4e48\u610f\u601d\" \/><\/p>\n<h3>Handler \u53d8\u6210 1<\/h3>\n<p>\u95ee\u9898\u53d1\u751f\u4e8e\u6628\u5929\uff0c\u6ca1\u60f3\u5230\u8fd9\u4e2a\u9879\u76ee\u8d8a\u6765\u8d8a\u5927\uff0c\u5bfc\u81f4\u8def\u7531\u592a\u591a\uff0c\u5c31\u53c2\u7167\u7f51\u4e0a\u4e00\u4e2a\u4eba\u7684\u6587\u7ae0\uff0c\u628a\u8def\u7531\u62c6\u5206\u4e86\u3002 \u6ca1\u60f3\u5230\uff0c\u62c6\u5206\u540e\uff0c\u6240\u6709\u7684 Handlers \u90fd\u53d8\u6210\u4e86 1\uff0c\u5982\u4e0b\u56fe\uff1a <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/09\/20200925_5f6d6ea6da50b.png\" alt=\"Gin \u542f\u52a8\u4e4b\u540e, \u8def\u7531\u540e\u9762\u7684 Handlers \u6570\u91cf\u662f\u4ec0\u4e48\u610f\u601d\" \/><\/p>\n<p>\u60f3\u95ee\u4e00\u4e0b\u5404\u4f4d\u5927\u4f6c\uff0c\u8fd9\u6837\u7684\u8bdd\uff0c\u4f1a\u4e0d\u4f1a\u5bf9\u6211\u7684\u9879\u76ee\u6027\u80fd\u4ea7\u751f\u5f71\u54cd~~~<\/p>\n<p>\u987a\u4fbf\u5949\u529d\u5927\u5bb6\uff0c\u4e0d\u8981\u968f\u4fbf\u76f8\u4fe1\u7f51\u4e0a\u7684\u6587\u7ae0 T_T<\/p>\n<h3>\u62c6\u5206\u65b9\u5f0f<\/h3>\n<p>\u62c6\u5206\u8def\u7531\u5668\u7684\u65b9\u5f0f\uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/09\/20200925_5f6d6ea717293.png\" alt=\"Gin \u542f\u52a8\u4e4b\u540e, \u8def\u7531\u540e\u9762\u7684 Handlers \u6570\u91cf\u662f\u4ec0\u4e48\u610f\u601d\" \/><\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3438331\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : labulaka521 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5e94\u8be5\u662f\u4f60\u7684\u4e2d\u95f4\u4ef6\u6570\u91cf+\u4f60\u7684\u4e1a\u52a1\u5904\u7406\u51fd\u6570(1)<br \/>\u4e5f\u5c31\u662f RouterGroup \u8fd9\u4e2a\u7ed3\u6784\u4f53\u7684 Handlers \u53c2\u6570<br \/>\u53ef\u4ee5\u770b\u770b gin \u6240\u4f7f\u7528\u7684 httprouter                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3438332\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : richzhu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @labulaka521 \u4e2d\u95f4\u4ef6\u4e00\u76f4\u90fd\u53ea\u6709 1 \u4e2a\u5462\uff0c\u62c6\u5206\u4e4b\u524d\u662f 4\uff0c\u62c6\u5206\u540e\u5c31\u53d8\u6210 1 \u4e86\uff0c\u8bf7\u95ee\u8fd9\u4e2a\u4ece 4 \u53d8\u6210\u4e86 1\uff0c\u5bf9\u6027\u80fd\u6709\u5f71\u54cd\u561b\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3438333\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Abirdcfly <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u663e\u793a\u8fd9\u4e2a\u90e8\u5206\u5728 debugPrintRoute \u51fd\u6570<br \/>&#8220;&#8220;<br \/>func debugPrintRoute( httpMethod, absolutePath string, handlers HandlersChain) {<br \/> if IsDebugging() {<br \/> nuHandlers := len(handlers)<br \/> for _, h := range handlers{ \/\/<br \/> debugPrint(&#8221; %s&#8221;, nameOfFunction(h)) \/\/\u8fd9\u4e24\u884c\u662f\u6211\u52a0\u7684\u3002\u770b\u4e00\u4e0b\u662f\u5565\u5c31\u77e5\u9053\u8fd9 4 \u4e2a\u662f\u4ec0\u4e48 handler \u4e86\u3002<br \/> }<br \/> handlerName := nameOfFunction(handlers.Last())<br \/> if DebugPrintRouteFunc == nil {<br \/> debugPrint(&#8220;%-6s %-25s &#8211;&gt; %s (%d handlers)n&#8221;, httpMethod, absolutePath, handlerName, nuHandlers)<br \/> } else {<br \/> DebugPrintRouteFunc( httpMethod, absolutePath, handlerName, nuHandlers)<br \/> }<br \/> }<br \/>}<br \/>&#8220;&#8220;<\/p>\n<p>\u6211\u8fd9\u91cc\u9664\u53bb\u90a3\u4e2a\u4e1a\u52a1\u903b\u8f91\u51fd\u6570\u5916\uff0c\u5269\u4e0b\u7684 3 \u4e2a handler \u662f<br \/>github.com\/gin-gonic\/gin.LoggerWithConfig.func1<br \/>github.com\/gin-gonic\/gin.RecoveryWithWriter.func1<br \/>github.com\/gin-contrib\/cors.New.func1                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3438334\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : richzhu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Abirdcfly \u771f\u5927\u4f6c\uff01\u7591\u60d1\u89e3\u51b3\u4e86~ \u975e\u5e38\u611f\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Gin \u542f\u52a8\u4e4b\u540e, \u8def\u7531\u540e\u9762\u7684 H&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/159638"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=159638"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/159638\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=159638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=159638"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=159638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}