1 Star 4 Fork 1

Lewis / gino

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.go 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
Lewis 提交于 2022-06-02 13:29 . 去除测试文件
package main
import (
"fmt"
"gino/boot"
"gino/global"
"gino/router"
"github.com/gin-gonic/gin"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
// 路由初始化
r := router.InitRouter()
// 设置Gin模式
gin.SetMode(global.Config.App.RunMode)
// API SERVER
srv := &http.Server{
Addr: global.Config.App.Addr,
Handler: r.GinEngine,
ReadTimeout: global.Config.App.ReadTimeout * time.Second,
WriteTimeout: global.Config.App.WriteTimeout * time.Second,
MaxHeaderBytes: 1 << 20, // 1 MB
}
log.Printf("server start on %s", global.Config.App.Addr)
go func() {
if err := srv.ListenAndServe(); err != nil {
panic(fmt.Sprintf("listen error: %s\n", err))
}
}()
// 分布式cron
redisLock, ok := boot.AcquireCron()
if ok {
defer redisLock.Release()
}
// 等待 syscall.SIGINT syscall.SIGTERM 优雅地关闭服务器
// 超时 5秒
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("Shutdown Server ...")
//ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
//log.Printf("%+v", ctx)
//defer cancel()
//if err := srv.Shutdown(ctx); err != nil {
// panic(fmt.Sprintf("Server Shutdown: %s\n", err))
//}
//log.Println("Server exiting")
// 程序结束前关闭Redis链接
defer global.Redis.Close()
}
Go
1
https://gitee.com/tfc2016/gino.git
git@gitee.com:tfc2016/gino.git
tfc2016
gino
gino
master

搜索帮助