api_test_logic.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package logic
  2. import (
  3. "call_center/db/rpc/pb"
  4. "context"
  5. "encoding/json"
  6. "log"
  7. "call_center/db/api/internal/svc"
  8. "call_center/db/api/internal/types"
  9. "github.com/tal-tech/go-zero/core/logx"
  10. )
  11. type ApiTestLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewApiTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) ApiTestLogic {
  17. return ApiTestLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func (l *ApiTestLogic) ApiTest(req types.Request) (*types.Response, error) {
  24. msgReq := new(pb.DbMsgReq)
  25. cmd := new(pb.DbCommandMsg)
  26. cmd.CmdType = pb.EDbCommand_E_DB_COMMAND_GET_CONFIG
  27. msgReq.Cmd = cmd
  28. res, err := l.svcCtx.DbRpc.DbCall(l.ctx, msgReq)
  29. if err != nil {
  30. return nil, err
  31. }
  32. confList := res.GetCmd().GetArrayConfig().GetDataList()
  33. for _, conf := range confList {
  34. var confValueMap map[string]interface{}
  35. confName := conf.ConfName
  36. confKey := conf.ConfKey
  37. err = json.Unmarshal([]byte(conf.ConfValue), &confValueMap)
  38. if err != nil {
  39. continue
  40. }
  41. log.Println(confName, confKey, confValueMap)
  42. }
  43. log.Println("<ApiTest>")
  44. return &types.Response{
  45. Res: 1,
  46. }, nil
  47. }