error_code_add.go 894 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package error_code
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/common.in/utils"
  6. "gd_management/errors"
  7. "fmt"
  8. "github.com/astaxie/beego/orm"
  9. "go.uber.org/zap"
  10. )
  11. func addErrorCode(req *apis.ManagementAddErrorReq) (int64, error) {
  12. dbstruct := &apis.TGdErrorCode{
  13. Code: req.Code,
  14. Msg: req.Msg,
  15. }
  16. o := orm.NewOrm()
  17. id, err := o.Insert(dbstruct)
  18. if err != nil {
  19. fmt.Printf("database err:%v\n", err)
  20. return 0, errors.DataBaseError
  21. }
  22. return int64(id), nil
  23. }
  24. func ManagementAddError(ctx context.Context, req *apis.ManagementAddErrorReq, reply *apis.ManagementAddErrorReply) (err error) {
  25. id, err := addErrorCode(req)
  26. if err != nil {
  27. l.Error("func",
  28. zap.String("call", "ManagementAddError"),
  29. zap.String("args", utils.MarshalJsonString(req)),
  30. zap.String("error", err.Error()))
  31. }
  32. reply.Id = id
  33. l.Debug(utils.MarshalJsonString(req, reply))
  34. return
  35. }