第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我正常停止http.ListenAndServe失敗

我正常停止http.ListenAndServe失敗

Go
臨摹微笑 2021-04-09 22:18:02
我是Go程序員的新手。我正在編寫一個Web應(yīng)用程序,我需要服務(wù)器等待活動請求發(fā)出后再關(guān)閉。我寫了一個處理程序,等待5秒鐘回答。如果我發(fā)出請求并停止服務(wù)器(在5秒鐘之前),則會收到“無法連接”錯誤。有沒有一種方法可以停止監(jiān)聽新請求并等待活動請求完成?這是我的例子func main() {    log.Infof("Starting (PID %d)...", os.Getpid())    stop := make(chan os.Signal, 1)    signal.Notify(stop, syscall.SIGTERM)    signal.Notify(stop, syscall.SIGINT)    listenAt := "127.0.0.1:8000"    r := newRouter()    h := &http.Server{Addr: listenAt, Handler: r}    go func() {        log.Info("Serving on http://", listenAt)        if err := h.ListenAndServe(); err != nil {            log.Fatal(err)        }    }()    <-stop    log.Info("Stoping ...")    h.Shutdown(context.Background())    log.Info("Bye :)")}示例處理程序func handler(w http.ResponseWriter, r *http.Request) {    time.Sleep(5 * time.Second)    log.Info("new request")    fmt.Fprintf(w, "Hola!")}完整示例@ https://gist.github.com/nachopro/d80fa71ae49527e1ddcaf359b4ff488b
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 547 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號