71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"hc/route"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"time"
|
|
|
|
//"hc/device
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/shockliu/logger"
|
|
)
|
|
|
|
const version = "2.0.1"
|
|
|
|
func main() {
|
|
port := flag.Int("port", 8012, "端口")
|
|
flag.Parse()
|
|
logger.Debugf("端口参数%d\n", *port)
|
|
fmt.Printf("\n\n\n")
|
|
fmt.Printf(" **************************************************\n")
|
|
fmt.Printf(" * \033[1;34;42m康养项目微信服务支撑平台\033[0m *\n")
|
|
fmt.Printf(" * ========================================= *\n")
|
|
fmt.Printf(" * 版本: %v *\n", version)
|
|
fmt.Printf(" * 技术支持:\033[1;32;40m豆曲咖莱(杭州)科技有限公司\033[0m *\n")
|
|
fmt.Printf(" * Email: \033[1;32;40msales@daymele.com\033[0m *\n")
|
|
fmt.Printf(" **************************************************\n")
|
|
fmt.Printf("\n\n")
|
|
|
|
// go mpoa.UserProc()
|
|
// go device.Maintain()
|
|
gin.SetMode(gin.ReleaseMode)
|
|
r := gin.Default()
|
|
route.Route(r)
|
|
|
|
fmt.Printf("康养微信服务端口:%d\n", *port)
|
|
// err := r.Run(":8012")
|
|
// if err != nil {
|
|
// fmt.Printf("start server error , err=%v", err)
|
|
// }
|
|
|
|
// 使用http启动服务
|
|
srv := &http.Server{
|
|
Addr: fmt.Sprintf(":%d", *port),
|
|
Handler: r,
|
|
}
|
|
go func() {
|
|
// 服务连接
|
|
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
|
logger.Fatalf("listen: %s\n", err)
|
|
}
|
|
}()
|
|
// 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间)
|
|
quit := make(chan os.Signal)
|
|
signal.Notify(quit, os.Interrupt)
|
|
<-quit
|
|
logger.Info("Shutdown Server ...")
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
if err := srv.Shutdown(ctx); err != nil {
|
|
logger.Fatal("Server Shutdown:", err)
|
|
}
|
|
logger.Info("Server exiting")
|
|
|
|
}
|