1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package http
- import (
- "net/http"
- "go-common/app/job/main/passport/conf"
- "go-common/app/job/main/passport/service"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- )
- var (
- srv *service.Service
- )
- // Init init http sever instance.
- func Init(c *conf.Config, s *service.Service) {
- srv = s
- // init inner router
- // engine
- engIn := bm.DefaultServer(c.BM)
- innerRouter(engIn)
- // init inner server
- if err := engIn.Start(); err != nil {
- log.Error("bm.Start error(%v)", err)
- panic(err)
- }
- }
- // innerRouter init inner router.
- func innerRouter(e *bm.Engine) {
- e.Ping(ping)
- }
- // ping check server ok.
- func ping(c *bm.Context) {
- if err := srv.Ping(c); err != nil {
- log.Error("ping error(%v)", err)
- c.AbortWithStatus(http.StatusServiceUnavailable)
- }
- }
|