http.go 962 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/live/xrewardcenter/conf"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/verify"
  8. )
  9. var (
  10. //midAuth *auth.Auth
  11. vfy *verify.Verify
  12. )
  13. // Init init
  14. func Init(c *conf.Config) {
  15. vfy = verify.New(c.Verify)
  16. engine := bm.DefaultServer(c.BM)
  17. route(engine)
  18. if err := engine.Start(); err != nil {
  19. log.Error("bm Start error(%v)", err)
  20. panic(err)
  21. }
  22. }
  23. func route(e *bm.Engine) {
  24. e.Ping(ping)
  25. e.Register(register)
  26. //midMap := map[string]bm.HandlerFunc{"auth": midAuth.User, "verify": vfy.Verify}
  27. g := e.Group("/x/xrewardcenter")
  28. {
  29. g.GET("/start", vfy.Verify, howToStart)
  30. }
  31. }
  32. func ping(c *bm.Context) {
  33. c.AbortWithStatus(http.StatusOK)
  34. }
  35. func register(c *bm.Context) {
  36. c.JSON(map[string]interface{}{}, nil)
  37. }
  38. // example for http request handler
  39. func howToStart(c *bm.Context) {
  40. c.String(0, "Golang 大法好 !!!")
  41. }