doc.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. // doc get document
  10. func doc(c *bm.Context) {
  11. params := c.Request.Form
  12. tsStr := params.Get("timestamp")
  13. moduleKey := params.Get("module_key")
  14. checkSumStr := params.Get("check_sum")
  15. // check login
  16. midIf, _ := c.Get("mid")
  17. mid := midIf.(int64)
  18. ts, err := strconv.ParseInt(tsStr, 10, 64)
  19. if err != nil {
  20. log.Error("strconv.ParseInt64(%v) error(%v)", tsStr, err)
  21. c.JSON(nil, ecode.RequestErr)
  22. return
  23. }
  24. checkSum, err := strconv.ParseInt(checkSumStr, 10, 64)
  25. if err != nil {
  26. log.Error("strconv.ParseInt64(%v) error(%v)", checkSumStr, err)
  27. c.JSON(nil, ecode.RequestErr)
  28. return
  29. }
  30. // doc
  31. data, err := kvoSvr.Document(c, mid, moduleKey, ts, checkSum)
  32. if err != nil {
  33. if ecode.Cause(err) != ecode.NotModified {
  34. log.Error("kvoSvr.Document(%v,%v) error(%v)", mid, moduleKey, err)
  35. }
  36. c.JSON(nil, err)
  37. return
  38. }
  39. c.JSON(data, nil)
  40. }
  41. // addDoc add document
  42. func addDoc(c *bm.Context) {
  43. params := c.Request.Form
  44. data := params.Get("data")
  45. tsStr := params.Get("timestamp")
  46. checkSumStr := params.Get("check_sum")
  47. moduleKey := params.Get("module_key")
  48. // check login
  49. midIf, _ := c.Get("mid")
  50. mid := midIf.(int64)
  51. ts, err := strconv.ParseInt(tsStr, 10, 64)
  52. if err != nil {
  53. log.Error("strconv.ParseInt64(%v) error(%v)", tsStr, err)
  54. c.JSON(nil, ecode.RequestErr)
  55. return
  56. }
  57. checkSum, err := strconv.ParseInt(checkSumStr, 10, 64)
  58. if err != nil {
  59. log.Error("strconv.ParseInt64(%v) error(%v)", checkSumStr, err)
  60. c.JSON(nil, ecode.RequestErr)
  61. return
  62. }
  63. // add doc
  64. resp, err := kvoSvr.AddDocument(c, mid, moduleKey, data, ts, checkSum, time.Now())
  65. if err != nil {
  66. if ecode.Cause(err) != ecode.NotModified {
  67. log.Error("kvoSvr.AddDocument(%v,%v,%v,%v,%v) error(%v)", mid, moduleKey, data, ts, checkSum, err)
  68. }
  69. c.JSON(nil, err)
  70. return
  71. }
  72. c.JSON(resp, nil)
  73. }