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
发布评论