Files
mir-godot/service/main.go

60 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-03-03 22:59:18 +08:00
/**
2024-03-06 10:47:22 +08:00
#*****************************************************************************
2024-08-06 18:30:21 +08:00
# @author MakerYang
# @site mir2.makeryang.com
2024-03-06 10:47:22 +08:00
#*****************************************************************************
*/
2024-03-03 22:59:18 +08:00
2024-08-06 18:30:21 +08:00
package main
2024-03-03 22:59:18 +08:00
import (
2024-08-06 18:30:21 +08:00
"Service/framework"
"Service/framework/config"
"Service/framework/router"
2024-03-03 22:59:18 +08:00
"context"
"fmt"
"github.com/gookit/color"
"log"
"net/http"
"os"
"os/signal"
"time"
)
2024-08-06 18:30:21 +08:00
func init() {
Framework.Init()
2024-03-03 22:59:18 +08:00
}
2024-08-06 18:30:21 +08:00
func main() {
// 设置log的Flag为0移除所有前缀包括时间
log.SetFlags(0)
2024-03-06 10:47:22 +08:00
2024-08-06 18:30:21 +08:00
RouterInit := Router.Init()
2024-03-03 22:59:18 +08:00
var HttpServer = &http.Server{
Addr: fmt.Sprintf(":%d", Config.Get.Service.HttpPort),
2024-08-06 18:30:21 +08:00
Handler: RouterInit,
2024-03-03 22:59:18 +08:00
ReadTimeout: Config.Get.Service.ReadTimeout,
WriteTimeout: Config.Get.Service.WriteTimeout,
MaxHeaderBytes: 1 << 20,
}
go func() {
if err := HttpServer.ListenAndServe(); err != nil {
}
}()
2024-08-06 18:30:21 +08:00
log.Println("[main]", color.Green.Text("server..."))
2024-03-03 22:59:18 +08:00
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := HttpServer.Shutdown(ctx); err != nil {
}
}