{"id":184023,"date":"2020-10-29T23:10:09","date_gmt":"2020-10-29T15:10:09","guid":{"rendered":"http:\/\/4563.org\/?p=184023"},"modified":"2020-10-29T23:10:09","modified_gmt":"2020-10-29T15:10:09","slug":"%e6%b1%82%e9%97%ae-golang-web-%e6%9c%8d%e5%8a%a1%e7%9a%84%e8%87%aa%e5%8a%a8%e9%87%8d%e5%90%af%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=184023","title":{"rendered":"\u6c42\u95ee Golang Web \u670d\u52a1\u7684\u81ea\u52a8\u91cd\u542f\u65b9\u6848"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6c42\u95ee Golang Web \u670d\u52a1\u7684\u81ea\u52a8\u91cd\u542f\u65b9\u6848               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ksedz <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u73b0\u5728\u7684 Web \u670d\u52a1\u7531\u4e8e\u4e00\u4e9b bug\uff0c\u4f1a\u5bfc\u81f4\u670d\u52a1\u5b95\u6389<\/p>\n<p>\u81ea\u52a8\u7684 recover \u4e2d\u95f4\u4ef6\u7b49\u53ea\u80fd\u5904\u7406\u5f53\u524d goroutine \u4e2d\u7684 panic\uff0c\u5982\u679c\u6bcf\u4e2a goroutine \u90fd\u8981 recover \u5904\u7406\u4e0b\u5c31\u592a\u9ebb\u70e6\u4e86\uff0c\u800c\u4e14\u4e5f\u4e0d\u80fd\u6709\u6548\u6392\u9664\u540e\u7eed\u7ef4\u62a4\u4eba\u5458\u7684\u5077\u61d2\u6216\u5931\u8bef<\/p>\n<p>\u770b\u4e86\u4e00\u4e9b\u76f8\u5173\u6a21\u5757\uff0c\u6ca1\u6709\u592a\u6ee1\u610f\u7684\uff0c\u671f\u671b\u7684\u662f\u50cf supervisor \u7684\u90a3\u6837\u7684\u529f\u80fd\uff0c\u4f46\u662f\u4e0d\u60f3\u7528 python \u5305\uff0c\u4e5f\u60f3\u7528\u66f4\u8f7b\u91cf\u7ea7\u7684\u65b9\u6848\u3002<\/p>\n<p>\u6c42\u95ee\u5927\u5bb6\u662f\u600e\u4e48\u89e3\u51b3\u7684\u3002      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>20<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3966852\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : susecjh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             docker                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966853\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : DoctorCat <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5199\u4e2a\u770b\u95e8\u72d7\u811a\u672c\uff0c\u4f8b\u5982 kill YourGoService &amp;&amp; .\/YourGoService \u7136\u540e cronjob \u5b9a\u671f\u8fd0\u884c\u4e00\u6b21                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966854\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Maboroshii <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             systemd                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966855\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : meshell <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u53ef\u80fd\u7528 supervisor \u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966856\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 676529483 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u865a\u673a\u8d77\u5c31 systemd\uff0c\u5bb9\u5668\u5c31 docker &#8211;restart=always                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966857\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : coderxy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             docker \u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966858\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wellsc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             systemd                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966859\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zunceng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u7684 http \u6846\u67b6\u6700\u597d\u53ef\u4ee5\u652f\u6301 HandleChain \u8fd9\u6837\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2a recover \u7684\u4e2d\u95f4\u4ef6<\/p>\n<p>func HandleRecover(ctx webFrame.Context) {<br \/> ctx.Next()<br \/> if err := recover();err != nil {<br \/> \/\/ print err<br \/> }<br \/>}<\/p>\n<p>\u7136\u540e\u628a\u8fd9\u4e2a\u4e2d\u95f4\u4ef6\u52a0\u5728 HandleChain \u7684\u7b2c\u4e00\u4e2a \u5c31\u53ef\u4ee5\u4e86<\/p>\n<p>router.use(HandleRecover)<\/p>\n<p>\u6700\u7b80\u5355\u7684 \u76f4\u63a5\u7528\u6210\u719f\u7684 http \u6846\u67b6 \u6bd4\u5982\u8bf4 gin \u81ea\u5e26 recover                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966860\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dongisking <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6700\u597d\u7684\u8fd8\u662f systemd \u548c docker                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966861\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : coderxy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zunceng \u6ca1\u7528\u7684\uff0cgo \u91cc\u9762\u5f00\u542f\u4e00\u4e2a\u65b0\u7684\u534f\u7a0b\u5c31\u5f97\u91cd\u65b0\u6355\u83b7\uff0c\u4e0d\u7136\u6574\u4e2a\u7a0b\u5e8f\u5c31\u4f1a crash \u3002\u800c\u4e14\u4f60\u8fd9\u4e2a\u5199\u7684\u4e5f\u4e0d\u5bf9\uff0cctx.next()\u5e94\u8be5\u653e\u5728 recover \u540e\u9762\uff0c\u800c\u4e14\u8fd8\u6709\u653e\u5230 defer \u91cc\u3002\u4e0d\u7136 ctx.next()\u5148\u6267\u884c\uff0c\u91cc\u9762\u6709 panic \u4f60\u7684\u7a0b\u5e8f\u5c31 crash \u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966862\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : index90 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528\u8fdb\u7a0b\u5b88\u62a4\u5c31\u4e0d\u6015\u4e2d\u65ad\u670d\u52a1\u4e2d\u65ad\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966863\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : MarksGui <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zunceng \u5728\u65b9\u6cd5\u5185\u90e8\u65b0\u5f00\u7684 goroutine panic \u662f\u65e0\u6cd5\u88ab\u7edf\u4e00\u7684 recover \u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966864\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cheng6563 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5199\u4e00\u4e2a\u5065\u5eb7\u68c0\u67e5\u7684\u63a5\u53e3\u3002<br \/>\u5916\u90e8\u7528 systemd \u6216\u8005 docker \u4e4b\u7c7b\u7684\u8fdb\u884c\u5065\u5eb7\u68c0\u67e5\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966865\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SingeeKing <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             service \u5916\u9762\u5305\u88f9\u4e00\u5c42\u81ea\u52a8\u91cd\u542f\u7684\u8f6f\u4ef6\uff0c\u4f8b\u5982\u5229\u7528 supervisor \/ pm2 \u505a\u7ba1\u7406                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966866\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SingeeKing <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6ca1\u7ec6\u770b\uff0clz \u662f\u4e0d\u662f\u5bf9 supervisor \u6709\u8bef\u89e3\uff0csupervisor \u53ea\u662f\u7528 Python \u5199\u7684\uff0c\u53ef\u4ee5\u7ba1\u7406\u4efb\u4f55\u8fdb\u7a0b\u800c\u4e0d\u662f\u53ea\u80fd\u7ba1\u7406 python \u7a0b\u5e8f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966867\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : janxin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u8fdb\u7a0b\u90fd\u5d29\u4e86\uff0c\u5f88\u591a\u4fe1\u606f\u4f1a\u4e22\u7684\uff0c\u4f60\u786e\u5b9a\u8fd9\u6837\u6ca1\u95ee\u9898\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966868\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : outoftimeerror <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             docker+k8s                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966869\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : freestyle <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             golang \u7248 supervisord\uff0c\u4e0d\u9700\u8981 Python \u73af\u5883\uff0c\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6\u52a0\u914d\u7f6e\u6587\u4ef6 https:\/\/github.com\/ochinchina\/supervisord                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966870\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ArJun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             docker \u6700\u597d\u7528                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3966871\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ericgui <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zunceng \u91cd\u542f\u8fd8\u662f\u8981\u9760\u7cfb\u7edf\u5c42\u9762\u89e3\u51b3\uff0c\u6bd4\u5982\u5185\u5b58\u6cc4\u9732\u548b\u529e\uff0c\u8fd9 recover \u5c31\u6ca1\u7528\u4e86\uff0c\u5e73\u65f6\u6bcf\u6b21\u6267\u884c\u90fd if else \u4e00\u4e0b\uff0c\u5176\u5b9e\u6d6a\u8d39\u6027\u80fd                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6c42\u95ee Golang Web \u670d\u52a1\u7684&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\/184023"}],"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=184023"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/184023\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184023"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}