NoContext - Graceful Stop

xuanbao · · 471 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>For web apps that don&#39;t have long running or complex request handling processes and Context is not a viable or desirable option such as with some middle ware. </p> <p>1 Issue stop command via some mechanism such as http request.<br/> 2 Block incoming requests and respond with SystemUnavailable.<br/> 3 Before shutdown, allow time for running requests to complete. </p> <p>You could save a few lines in your handler funcs with a handler wrapper func, but I think they&#39;re ugly. </p> <p>I&#39;m not sure about putting os.Exit inside a handler, but the code seems to work ok. Suggestions/warnings welcome. </p> <p><a href="https://play.golang.org/p/qNsnkSzCpl" rel="nofollow">Code On Playground</a></p> <hr/>**评论:**<br/><br/>rz2yoj: <pre><p>Is there something preventing you from using <code>http.Server.Shutdown</code>?</p></pre>jayposs: <pre><p>I don&#39;t typically use the built in http router.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

471 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传