go-common/app/job/main/reply-feed/server/http/http.go

42 lines
744 B
Go
Raw Normal View History

2019-04-22 10:49:16 +00:00
package http
import (
"net/http"
"go-common/app/job/main/reply-feed/conf"
"go-common/app/job/main/reply-feed/service"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
var (
svc *service.Service
)
// Init init
func Init(c *conf.Config, s *service.Service) {
svc = s
engine := bm.DefaultServer(c.BM)
router(engine)
if err := engine.Start(); err != nil {
log.Error("engine.Start error(%v)", err)
panic(err)
}
}
func router(e *bm.Engine) {
e.Ping(ping)
e.Register(register)
}
func ping(c *bm.Context) {
if err := svc.Ping(c); err != nil {
log.Error("ping error(%v)", err)
c.AbortWithStatus(http.StatusServiceUnavailable)
}
}
func register(c *bm.Context) {
c.JSON(map[string]interface{}{}, nil)
}