You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cronsun/bin/web/server.go

53 lines
926 B

8 years ago
package main
import (
"net"
"github.com/cockroachdb/cmux"
"sunteng/commons/event"
"sunteng/commons/log"
"sunteng/cronsun/conf"
"sunteng/cronsun/models"
8 years ago
"sunteng/cronsun/web"
)
func main() {
if err := models.Init(); err != nil {
log.Error(err.Error())
return
}
8 years ago
l, err := net.Listen("tcp", conf.Config.Web.BindAddr)
if err != nil {
log.Error(err.Error())
return
8 years ago
}
// Create a cmux.
m := cmux.New(l)
httpL := m.Match(cmux.HTTP1Fast())
httpServer, err := web.InitRouters()
if err != nil {
log.Error(err.Error())
return
8 years ago
}
go func() {
err := httpServer.Serve(httpL)
if err != nil {
panic(err.Error())
}
}()
go m.Serve()
8 years ago
log.Noticef("cronsun web server started on %s, Ctrl+C or send kill sign to exit", conf.Config.Web.BindAddr)
// 注册退出事件
// event.On(event.EXIT, n.Stop)
// 监听退出信号
event.Wait()
event.Emit(event.EXIT, nil)
log.Notice("exit success")
}