ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` package main import ( "context" "log" "net/http" "os" "os/signal" "time" "github.com/gin-gonic/gin" _ "kefu-work/libs/mysql" _ "kefu-work/libs/redis" "project/router" ) func main() { routers := gin.New() // 初始化路由 router.ApiInit(routers) srv := &http.Server{ Addr: ":8080", Handler: routers, } go func() { // 服务连接 if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { log.Fatalf("listen: %s\n", err) } }() // 等待中断信号以优雅地关闭服务器 quit := make(chan os.Signal) signal.Notify(quit, os.Interrupt) <-quit log.Println("Shutdown Server ...") ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() if err := srv.Shutdown(ctx); err != nil { log.Fatal("Server Shutdown:", err) } log.Println("Server exiting") } ```