gaea.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package v1
  2. import (
  3. "context"
  4. "strconv"
  5. "google.golang.org/grpc/status"
  6. v1pb "go-common/app/admin/live/live-admin/api/http/v1"
  7. "go-common/app/admin/live/live-admin/conf"
  8. client "go-common/app/service/live/resource/api/grpc/v1"
  9. "go-common/library/ecode"
  10. )
  11. // GaeaService struct
  12. type GaeaService struct {
  13. conf *conf.Config
  14. client *client.Client
  15. // optionally add other properties here, such as dao
  16. // dao *dao.Dao
  17. }
  18. //NewGaeaService init
  19. func NewGaeaService(c *conf.Config) (s *GaeaService) {
  20. s = &GaeaService{
  21. conf: c,
  22. }
  23. s.client, _ = client.NewClient(c.ResourceClient)
  24. return s
  25. }
  26. // GetConfigByKeyword implementation
  27. // 获取team下某个keyword的配置 `internal:"true"`
  28. func (s *GaeaService) GetConfigByKeyword(ctx context.Context, req *v1pb.GetConfigReq) (resp *v1pb.GetConfigResp, err error) {
  29. resp = &v1pb.GetConfigResp{}
  30. if "" == req.GetKeyword() || 0 == req.GetTeam() {
  31. err = ecode.Error(1, "参数错误")
  32. return
  33. }
  34. ret, err := s.client.GetConfigByKeyword(ctx, &client.GetConfigReq{
  35. Team: req.GetTeam(),
  36. Keyword: req.GetKeyword(),
  37. })
  38. if err != nil {
  39. return
  40. }
  41. resp.Team = ret.Team
  42. resp.Keyword = ret.Keyword
  43. resp.Name = ret.Name
  44. resp.Value = ret.Value
  45. resp.Ctime = ret.Ctime
  46. resp.Mtime = ret.Mtime
  47. resp.Status = ret.Status
  48. resp.Id = ret.Id
  49. return
  50. }
  51. // SetConfigByKeyword implementation
  52. // 设置team下某个keyword配置 `internal:"true"`
  53. func (s *GaeaService) SetConfigByKeyword(ctx context.Context, req *v1pb.SetConfigReq) (resp *v1pb.SetConfigResp, err error) {
  54. resp = &v1pb.SetConfigResp{}
  55. if "" == req.GetKeyword() || len(req.GetKeyword()) > 16 {
  56. err = ecode.Error(1, "参数错误")
  57. return
  58. }
  59. ret, err := s.client.SetConfigByKeyword(ctx, &client.SetConfigReq{
  60. Team: req.GetTeam(),
  61. Keyword: req.GetKeyword(),
  62. Value: req.GetValue(),
  63. Name: req.GetName(),
  64. Id: req.GetId(),
  65. Status: req.GetStatus(),
  66. })
  67. if err != nil {
  68. return
  69. }
  70. resp.Id = ret.Id
  71. return
  72. }
  73. // GetConfigsByParams implementation
  74. // 管理后台根据条件获取配置 `internal:"true"`
  75. func (s *GaeaService) GetConfigsByParams(ctx context.Context, req *v1pb.ParamsConfigReq) (resp *v1pb.ParamsConfigResp, err error) {
  76. resp = &v1pb.ParamsConfigResp{}
  77. clientResp, err := s.client.GetConfigsByParams(ctx, &client.ParamsConfigReq{
  78. Team: req.GetTeam(),
  79. Keyword: req.GetKeyword(),
  80. Name: req.GetName(),
  81. Status: req.GetStatus(),
  82. Page: req.GetPage(),
  83. PageSize: req.GetPageSize(),
  84. Id: req.GetId(),
  85. })
  86. resp.TotalNum = clientResp.TotalNum
  87. resp.List = []*v1pb.List{}
  88. for _, v := range clientResp.List {
  89. detail := &v1pb.List{
  90. Id: v.Id,
  91. Team: v.Team,
  92. Keyword: v.Keyword,
  93. Name: v.Name,
  94. Value: v.Value,
  95. Ctime: v.Ctime,
  96. Mtime: v.Mtime,
  97. Status: v.Status,
  98. }
  99. resp.List = append(resp.List, detail)
  100. }
  101. if err != nil {
  102. return
  103. }
  104. return
  105. }
  106. // FormatErr format error msg
  107. func (s *GaeaService) FormatErr(statusCode *status.Status) (code int32, msg string) {
  108. gCode := statusCode.Code()
  109. code = 1
  110. if gCode == 2 {
  111. code, _ := strconv.Atoi(statusCode.Message())
  112. switch code {
  113. case 1:
  114. msg = "必要参数不正确"
  115. case 11:
  116. msg = "索引名称在分组内冲突"
  117. case -500:
  118. msg = "内部错误"
  119. default:
  120. msg = "内部错误"
  121. }
  122. } else {
  123. msg = "内部错误"
  124. }
  125. return
  126. }
  127. // GetConfigsByTeam implementation
  128. // 获取单个team的全部配置 `internal:"true"`
  129. func (s *GaeaService) GetConfigsByTeam(ctx context.Context, req *v1pb.TeamConfigReq) (resp *v1pb.TeamConfigResp, err error) {
  130. resp = &v1pb.TeamConfigResp{}
  131. return
  132. }
  133. // GetConfigsByKeyword implementation
  134. // 通过keyword获取配置 `internal:"true"`
  135. func (s *GaeaService) GetConfigsByKeyword(ctx context.Context, req *v1pb.GetConfigsReq) (resp *v1pb.GetConfigsResp, err error) {
  136. resp = &v1pb.GetConfigsResp{}
  137. return
  138. }
  139. // GetConfigsByTeams implementation
  140. // 获取多个team下的全部配置 `internal:"true"`
  141. func (s *GaeaService) GetConfigsByTeams(ctx context.Context, req *v1pb.TeamsConfigReq) (resp *v1pb.TeamsConfigResp, err error) {
  142. resp = &v1pb.TeamsConfigResp{}
  143. return
  144. }