Files
mir-godot/service/main.go
MakerYang a902dd3de7 new
2024-08-06 18:30:21 +08:00

60 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
#*****************************************************************************
# @author MakerYang
# @site mir2.makeryang.com
#*****************************************************************************
*/
package main
import (
"Service/framework"
"Service/framework/config"
"Service/framework/router"
"context"
"fmt"
"github.com/gookit/color"
"log"
"net/http"
"os"
"os/signal"
"time"
)
func init() {
Framework.Init()
}
func main() {
// 设置log的Flag为0移除所有前缀包括时间
log.SetFlags(0)
RouterInit := Router.Init()
var HttpServer = &http.Server{
Addr: fmt.Sprintf(":%d", Config.Get.Service.HttpPort),
Handler: RouterInit,
ReadTimeout: Config.Get.Service.ReadTimeout,
WriteTimeout: Config.Get.Service.WriteTimeout,
MaxHeaderBytes: 1 << 20,
}
go func() {
if err := HttpServer.ListenAndServe(); err != nil {
}
}()
log.Println("[main]", color.Green.Text("server..."))
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 {
}
}