upgrade.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package http
  2. import (
  3. "go-common/app/interface/main/tv/model"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. var (
  9. getForm = map[string]bool{
  10. "mobi_app": true,
  11. "build": true,
  12. "channel": true,
  13. "seed": true,
  14. "sdkint": false,
  15. "model": false,
  16. "old_id": false,
  17. }
  18. )
  19. func validatePostData(c *bm.Context, params map[string]bool) bool {
  20. for k, v := range params {
  21. if v {
  22. if c.Request.Form.Get(k) == "" {
  23. log.Error("The field is required(%s)", k)
  24. return false
  25. }
  26. }
  27. }
  28. return true
  29. }
  30. func upgrade(c *bm.Context) {
  31. var (
  32. req = c.Request.Form
  33. ver = &model.VerUpdate{
  34. MobiApp: req.Get("mobi_app"),
  35. Build: int(parseInt(req.Get("build"))),
  36. Channel: req.Get("channel"),
  37. Seed: int(parseInt(req.Get("seed"))),
  38. Sdkint: int(parseInt(req.Get("sdkint"))),
  39. Model: req.Get("model"),
  40. OldID: req.Get("old_id"),
  41. }
  42. )
  43. if !validatePostData(c, getForm) {
  44. c.JSONMap(map[string]interface{}{
  45. "code": ecode.RequestErr,
  46. "message": "lack of fields",
  47. }, nil)
  48. return
  49. }
  50. result, errCode, err := gobSvc.VerUpdate(c, ver)
  51. if err != nil {
  52. log.Error("[VerUpdate] Load App Upgrade Data, Err: %v", err)
  53. c.JSONMap(map[string]interface{}{
  54. "code": errCode,
  55. "message": "load data fail",
  56. }, nil)
  57. return
  58. }
  59. c.JSON(result, nil)
  60. }