apidoc.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**********************************************
  2. ** @Des: This file ...
  3. ** @Author: haodaquan
  4. ** @Date: 2017-09-08 17:48:30
  5. ** @Last Modified by: haodaquan
  6. ** @Last Modified time: 2017-09-09 18:50:41
  7. ***********************************************/
  8. package backgroundc
  9. import (
  10. "fmt"
  11. "time"
  12. "github.com/astaxie/beego"
  13. "wuyebaoxiuapi/models/backgroundm"
  14. )
  15. type ApiDocController struct {
  16. BaseController
  17. }
  18. func (self *ApiDocController) Index() {
  19. self.Data["pageTitle"] = "API文档"
  20. self.Data["ts"] = time.Now()
  21. grouplists := groupLists()
  22. self.Data["grouplists"] = grouplists
  23. groupId, _ := self.GetInt("id", 1)
  24. groupInfo, err := backgroundm.GroupGetById(groupId)
  25. if err != nil {
  26. fmt.Println("数据不存在")
  27. }
  28. //公共文档
  29. apiPublic, err := backgroundm.ApiPublicGetByIds(groupInfo.ApiPublicIds)
  30. self.Data["apiPublic"] = apiPublic
  31. //环境
  32. // env, err := models.EnvGetByIds(groupInfo.EnvIds)
  33. // self.Data["env"] = env
  34. // //状态码
  35. // code, err := models.CodeGetByIds(groupInfo.CodeIds)
  36. // self.Data["code"] = code
  37. //接口
  38. apiMenu, _ := backgroundm.ApiTreeData(groupId)
  39. self.Data["apiMenu"] = apiMenu
  40. self.Data["groupId"] = groupId
  41. self.TplName = "apidoc/index.html"
  42. }
  43. func (self *ApiDocController) Public() {
  44. apiPublicId, _ := self.GetInt("id", 1)
  45. apiPublic, _ := backgroundm.ApiPublicGetById(apiPublicId)
  46. self.Data["apiPublic"] = apiPublic
  47. self.TplName = "apidoc/apipublic.html"
  48. }
  49. func (self *ApiDocController) Env() {
  50. groupId, _ := self.GetInt("id", 0)
  51. groupInfo, _ := backgroundm.GroupGetById(groupId)
  52. env, _ := backgroundm.EnvGetByIds(groupInfo.EnvIds)
  53. self.Data["env"] = env
  54. self.TplName = "apidoc/env.html"
  55. }
  56. func (self *ApiDocController) Code() {
  57. groupId, _ := self.GetInt("id", 0)
  58. groupInfo, _ := backgroundm.GroupGetById(groupId)
  59. code, _ := backgroundm.CodeGetByIds(groupInfo.CodeIds)
  60. self.Data["code"] = code
  61. self.TplName = "apidoc/code.html"
  62. }
  63. func (self *ApiDocController) ApiDetail() {
  64. id, _ := self.GetInt("id", 0)
  65. detail, _ := backgroundm.ApiFullDetailById(id)
  66. row := make(map[string]interface{})
  67. row["id"] = detail.Id
  68. row["source_id"] = detail.SourceId
  69. row["api_url"] = detail.ApiUrl
  70. row["api_name"] = detail.ApiName
  71. row["detail"] = detail.Detail
  72. row["status"] = detail.Status
  73. row["create_name"] = detail.CreateName
  74. row["update_name"] = detail.UpdateName
  75. row["audit_name"] = detail.AuditName
  76. row["audit_status"] = AUDIT_STATUS[detail.Status]
  77. row["method"] = REQUEST_METHOD[detail.Method]
  78. row["audit_time"] = beego.Date(time.Unix(detail.AuditTime, 0), "Y-m-d H:i:s")
  79. row["update_time"] = beego.Date(time.Unix(detail.UpdateTime, 0), "Y-m-d H:i:s")
  80. self.Data["pageTitle"] = "查看 " + detail.ApiName
  81. self.Data["Detail"] = row
  82. self.TplName = "apidoc/apidetail.html"
  83. }