42 lines
744 B
Go
42 lines
744 B
Go
|
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)
|
||
|
}
|