MCPcopy Create free account
hub / github.com/LockGit/gochat / Run

Method Run

api/chat.go:32–67  ·  view source on GitHub ↗

api server,Also, you can use gin,echo ... framework wrap

()

Source from the content-addressed store, hash-verified

30
31//api server,Also, you can use gin,echo ... framework wrap
32func (c *Chat) Run() {
33 //init rpc client
34 rpc.InitLogicRpcClient()
35
36 r := router.Register()
37 runMode := config.GetGinRunMode()
38 logrus.Info("server start , now run mode is ", runMode)
39 gin.SetMode(runMode)
40 apiConfig := config.Conf.Api
41 port := apiConfig.ApiBase.ListenPort
42 flag.Parse()
43
44 srv := &http.Server{
45 Addr: fmt.Sprintf(":%d", port),
46 Handler: r,
47 }
48
49 go func() {
50 if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
51 logrus.Errorf("start listen : %s\n", err)
52 }
53 }()
54 // if have two quit signal , this signal will priority capture ,also can graceful shutdown
55 quit := make(chan os.Signal)
56 signal.Notify(quit, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
57 <-quit
58 logrus.Infof("Shutdown Server ...")
59
60 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
61 defer cancel()
62 if err := srv.Shutdown(ctx); err != nil {
63 logrus.Errorf("Server Shutdown:", err)
64 }
65 logrus.Infof("Server exiting")
66 os.Exit(0)
67}

Callers 1

mainFunction · 0.45

Calls 3

InitLogicRpcClientFunction · 0.92
RegisterFunction · 0.92
GetGinRunModeFunction · 0.92

Tested by

no test coverage detected