hook.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package http
  2. import (
  3. "go-common/app/admin/ep/tapd/model"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/binding"
  8. )
  9. const (
  10. _sessUnKey = "username"
  11. )
  12. func tapdCallback(c *bm.Context) {
  13. c.JSON(nil, svc.TapdCallBack(c, c.Request.Body))
  14. }
  15. func updateHook(c *bm.Context) {
  16. var (
  17. err error
  18. v = &model.HookURLUpdateReq{}
  19. username string
  20. )
  21. if err = c.BindWith(v, binding.JSON); err != nil {
  22. return
  23. }
  24. if username, err = getUsername(c); err != nil {
  25. return
  26. }
  27. c.JSON(svc.UpdateHookURL(c, username, v))
  28. }
  29. func queryHook(c *bm.Context) {
  30. var (
  31. v = &model.QueryHookURLReq{}
  32. err error
  33. )
  34. if err = c.BindWith(v, binding.JSON); err != nil {
  35. return
  36. }
  37. if err = v.Verify(); err != nil {
  38. c.JSON(nil, err)
  39. return
  40. }
  41. c.JSON(svc.QueryHookURL(c, v))
  42. }
  43. func queryURLEvent(c *bm.Context) {
  44. var (
  45. v = new(struct {
  46. ID int64 `form:"url_id"`
  47. })
  48. err error
  49. )
  50. if err = c.Bind(v); err != nil {
  51. return
  52. }
  53. c.JSON(svc.QueryURLEvent(c, v.ID))
  54. }
  55. func queryEventLog(c *bm.Context) {
  56. var (
  57. v = &model.QueryEventLogReq{}
  58. err error
  59. )
  60. if err = c.BindWith(v, binding.JSON); err != nil {
  61. return
  62. }
  63. if err = v.Verify(); err != nil {
  64. c.JSON(nil, err)
  65. return
  66. }
  67. c.JSON(svc.QueryEventLog(c, v))
  68. }
  69. func saveHookUrlInCache(c *bm.Context) {
  70. c.JSON(svc.SaveEnableHookURL(c))
  71. }
  72. func queryHookUrlInCache(c *bm.Context) {
  73. c.JSON(svc.QueryEnableHookURLInCache(c))
  74. }
  75. func test(c *bm.Context) {
  76. var (
  77. v = new(struct {
  78. Data interface{} `json:"data"`
  79. Code int `json:"code"`
  80. })
  81. err error
  82. )
  83. if err = c.BindWith(v, binding.JSON); err != nil {
  84. return
  85. }
  86. log.Info("WorkspaceID [%d]", v.Data)
  87. c.JSON(v, err)
  88. }
  89. func testform(c *bm.Context) {
  90. var (
  91. v = new(struct {
  92. ID string `form:"event"`
  93. })
  94. err error
  95. )
  96. if err = c.Bind(v); err != nil {
  97. return
  98. }
  99. log.Info("fengyifeng WorkspaceID", v.ID)
  100. c.JSON(v, err)
  101. }
  102. func getUsername(c *bm.Context) (username string, err error) {
  103. user, exist := c.Get(_sessUnKey)
  104. if !exist {
  105. err = ecode.AccessKeyErr
  106. c.JSON(nil, err)
  107. return
  108. }
  109. username = user.(string)
  110. return
  111. }