base_api_info.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package base_api
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/errors"
  6. "encoding/json"
  7. "strconv"
  8. "strings"
  9. "gd_management/common.in/utils"
  10. "github.com/astaxie/beego/orm"
  11. "go.uber.org/zap"
  12. )
  13. func ManagementGetBaseApiInfo(ctx context.Context, req *apis.ManagementGetBaseApiInfoReq, reply *apis.ManagementGetBaseApiInfoReply) (err error) {
  14. o := orm.NewOrm()
  15. dbInfo := apis.TGdApi{}
  16. err = o.QueryTable("t_gd_api").Filter("id", req.ApiId).One(&dbInfo)
  17. if err != nil {
  18. l.Error("func",
  19. zap.String("call", "ManagementGetBaseApiInfo"),
  20. zap.String("args", utils.MarshalJsonString(req)),
  21. zap.String("error", err.Error()))
  22. if err == orm.ErrNoRows {
  23. return errors.DataBaseNoRecord
  24. }
  25. return errors.DataBaseError
  26. }
  27. json.Unmarshal([]byte(dbInfo.RequestParam), &reply.BaseApiInfo.RequestParam)
  28. json.Unmarshal([]byte(dbInfo.ResponseParam), &reply.BaseApiInfo.ResponseParam)
  29. ids := strings.Split(dbInfo.ErrorCodeIds, ",")
  30. for _, v := range ids {
  31. id, _ := strconv.Atoi(v)
  32. reply.BaseApiInfo.ErrorCode = append(reply.BaseApiInfo.ErrorCode, id)
  33. }
  34. reply.BaseApiInfo.Method = dbInfo.Method
  35. reply.BaseApiInfo.Router = dbInfo.Router
  36. reply.BaseApiInfo.Name = dbInfo.Name
  37. reply.BaseApiInfo.Comment = dbInfo.Comment
  38. reply.BaseApiInfo.ThresholdTimeout = dbInfo.ThresholdTimeout
  39. reply.BaseApiInfo.ThresholdFailRate = dbInfo.ThresholdFailRate
  40. reply.BaseApiInfo.ThresholdNorecordRate = dbInfo.ThresholdNorecordRate
  41. reply.BaseApiInfo.Enable = dbInfo.Enable
  42. reply.BaseApiInfo.Type = dbInfo.ApiType
  43. l.Debug(utils.MarshalJsonString(req, reply))
  44. return
  45. }