From 586bee0df1461268542893ee29cd89f7491528fe Mon Sep 17 00:00:00 2001 From: JACKYMYPERSON Date: Wed, 24 Sep 2025 20:56:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9gin=E7=9A=84=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 563dfec..ab915a0 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,9 @@ package main import ( "log" + "net/http" "strconv" + "time" "toutoukan/controllers/search" "toutoukan/init/bleveInit" "toutoukan/init/config" @@ -28,9 +30,15 @@ func main() { panic(err) } r := router.SetupRouter() - err := r.Run(":" + strconv.Itoa(config.Conf.Port)) - if err != nil { - return + server := &http.Server{ + Addr: ":" + strconv.Itoa(config.Conf.Port), + Handler: r, + ReadTimeout: 5 * time.Second, // 客户端读取超时 + WriteTimeout: 10 * time.Second, // 服务端写入超时 + IdleTimeout: 30 * time.Second, // 空闲连接超时 + } + if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Fatalf("Server failed to start: %v", err) } defer func() { sqlDB, err := databaseInit.UserDB.DB()