1 Star 0 Fork 3

wuyulun/gin-api

forked from Eric-chy/gin-api 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"context"
"fmt"
_ "ginpro/boot"
"ginpro/config"
"ginpro/internal/router"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
//var g errgroup.Group
// @title gin系统
// @version 1.0
// @description gin开发的系统
// @termsOfService
func main() {
cfg := config.Conf.App
gin.SetMode(cfg.RunMode)
routers := router.ApiRouter()
var s *http.Server
go func() {
s = &http.Server{
Addr: ":" + cfg.Port,
Handler: routers,
ReadTimeout: cfg.ReadTimeout * time.Second,
WriteTimeout: cfg.WriteTimeout * time.Second,
MaxHeaderBytes: 1 << 20,
}
err := s.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
log.Fatalf("s.ListenAndServe error: %v", err)
}
}()
//等待中断信号
quit := make(chan os.Signal)
//接收syscall.SIGINT和syscall.SIGTERM信号
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
fmt.Println("Shutting down server...")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := s.Shutdown(ctx); err != nil {
fmt.Println("Server forced shutdown", err)
}
fmt.Println("Server existing")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wu--2019/gin-api.git
git@gitee.com:wu--2019/gin-api.git
wu--2019
gin-api
gin-api
main

搜索帮助