1 Star 0 Fork 0

treasure2020/go_gin_admin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
nightcp 提交于 2023-07-31 21:23 . init
package main
import (
"admin/core"
_ "admin/docs"
"admin/migration"
"admin/route"
"context"
"fmt"
"net/http"
"os"
"os/signal"
"time"
)
func main() {
if core.DB != nil {
db, _ := core.DB.DB()
defer db.Close()
}
migration.DBMigrate(core.DB)
migration.DBSeed(core.DB)
core.InitLogger()
r := route.InitRouter()
srv := &http.Server{
Addr: fmt.Sprintf(":%s", core.Config.ServerPort),
Handler: r,
ReadTimeout: time.Duration(core.Config.ReadTimeout) * time.Second,
WriteTimeout: time.Duration(core.Config.WriteTimeout) * time.Second,
}
go func() {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
core.Logger.Error(fmt.Sprintf("listen: %s", err))
}
}()
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
core.Logger.Info("Server shutdown ...")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
core.Logger.Error(fmt.Sprintf("Server shutdown: %s\n", err))
}
core.Logger.Info("Server exiting")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/nightcp/go_gin_admin.git
[email protected]:nightcp/go_gin_admin.git
nightcp
go_gin_admin
go_gin_admin
master

搜索帮助