-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun.go
44 lines (31 loc) · 882 Bytes
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package hfw
import (
"net/http"
"github.com/hsyan2008/hfw/common"
"github.com/hsyan2008/hfw/signal"
)
//Run start
func Run() (err error) {
signalContext := signal.GetSignalContext()
signalContext.Mix("Starting ...")
defer signalContext.Mix("Shutdowned!")
signalContext.Mixf("Running, VERSION=%s, ENVIRONMENT=%s, APPNAME=%s, APPPATH=%s",
common.GetVersion(), common.GetEnv(), common.GetAppName(), common.GetAppPath())
//监听信号
go signalContext.Listen()
//等待工作完成
defer signalContext.Shutdowned()
if len(Config.Server.Address) == 0 {
signalContext.Fatal("server address is nil")
<-signal.GetSignalContext().Ctx.Done()
return
}
//启动http
signalContext.IsHTTP = true
err = StartHTTP(Config.Server)
//如果未启动服务,就触发退出
if err != nil && err != http.ErrServerClosed {
signalContext.Fatal(err)
}
return
}