go http server graceful exit

编程入门 行业动态 更新时间:2024-10-15 14:19:09

go http <a href=https://www.elefans.com/category/jswz/34/1770992.html style=server graceful exit"/>

go http server graceful exit

今天做了一个go语音的http server优雅退出的测试实验

package mainimport ("context""fmt""log""net/http""os""os/signal""syscall""time"
)func main() {http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {t:=time.NewTimer(6 * time.Second)L: for {time.Sleep(1*time.Second)select {case <- t.C:fmt.Println("\ntime out===============================")break Ldefault:fmt.Println("i am doing job")}}fmt.Fprintf(w, "Hello World, %v\n", time.Now())})s := &http.Server{Addr:           ":8080",Handler:        http.DefaultServeMux,ReadTimeout:    10 * time.Second,WriteTimeout:   10 * time.Second,MaxHeaderBytes: 1 << 20,}go fun

更多推荐

go http server graceful exit

本文发布于:2024-02-19 13:17:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1764033.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:server   http   exit   graceful

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!