Golang优雅退出http server
来源:互联网 发布:黑帽seo劫持博客违法吗 编辑:程序博客网 时间:2024/06/07 21:49
最近经常听到“优雅”二字,很多人在谈代码的优雅。又碰巧看到了一段golang http server的“优雅”代码,大家共欣赏。
package mainimport ( "fmt" "net/http" "os" "os/signal" "syscall" "time")func main() { http.Handle("/", http.FileServer(http.Dir("."))) server := &http.Server{ Addr: ":4040", Handler: http.DefaultServeMux, } quitChan := make(chan os.Signal) signal.Notify(quitChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, ) go func() { fmt.Println(<-quitChan) server.Close() }() go server.ListenAndServe() time.Sleep(2 * time.Second) quitChan <- syscall.SIGINT time.Sleep(1 * time.Second)}
这里说的优雅,就是主动接收“退出信号”,关闭服务。
0 0
- Golang优雅退出http server
- golang如何优雅处理退出
- Golang Http Server源码阅读
- Golang Http Server源码阅读
- Golang Http Server源码阅读
- golang http server源码解读
- HTTP server connection draining(http server优雅的关闭)
- 热重启golang服务器(graceful restart golang http server)
- golang http server 源码解析与说明
- golang-net/http源码分析之http server
- 应用的优雅退出
- 优雅地退出应用
- Golang 如何优雅关闭 channel
- Golang 并发的退出
- golang 带托盘的 http server启动关闭服务
- Android 优雅地退出App
- 如何优雅的退出goroutine
- Golang Socket Tcp 连接优雅关闭
- iOS setStatusBarStyle没有效果
- JavaScript模块化开发一瞥
- 挂载 (mount) 深入理解
- selenium自动化测试框架搭建-思路,无代码
- 私活,永远解救不了自己屌丝的人生!
- Golang优雅退出http server
- springMVC 返回Json实体类属性自定义格式转换
- 虚拟机ubuntu16.04 安装caffe
- 图论算法-建图和最短路
- 入力規則とVisualforce DmlException
- Zephyr Kernel v1.7.0
- 【TX1学习与开发系列】交换空间与磁盘容量增加(二)
- SHA1算法实现及详解
- js基本知识比较系列二:DOM操作