resource.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package http
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "go-common/app/admin/main/aegis/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. )
  10. // SyncResource 同步到业务方
  11. func (d *Dao) SyncResource(c context.Context, act *model.Action, ropt map[string]interface{}) (code int, err error) {
  12. params := url.Values{}
  13. for k, v := range ropt {
  14. params.Set(k, fmt.Sprint(v))
  15. }
  16. requestParams := fmt.Sprintf("%s?%s", act.URL, params.Encode())
  17. log.Info("SyncResource url(%v) params(%s)", act.URL, params.Encode())
  18. if d.c.Debug == "local" || d.c.Debug == "nobusiness" {
  19. return
  20. }
  21. res := new(struct {
  22. Code int `json:"code"`
  23. Msg string `json:"msg"`
  24. Message string `json:"message"`
  25. })
  26. err = d.clientW.Post(c, act.URL, "", params, res)
  27. code = res.Code
  28. if err != nil || res.Code != 0 {
  29. log.Error("clientW.Post err(%v) response(%+v) request(%s)", err, res, requestParams)
  30. err = ecode.Errorf(ecode.AegisBusinessSyncErr, "业务回调错误 request(%s) httperror(%v) response(%+v)", requestParams, err, res)
  31. }
  32. return
  33. }