city_config_third.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package third
  2. import (
  3. "context"
  4. "go-template/business/dto"
  5. "go-template/business/exception"
  6. "gitea.ckfah.com/cjjy/gocommon/pkg/cerror"
  7. "gitea.ckfah.com/cjjy/gocommon/pkg/logger"
  8. "gitea.ckfah.com/cjjy/gocommon/pkg/net/httpclent"
  9. )
  10. type cityConfigThird struct {
  11. }
  12. func NewCityConfigThird() *cityConfigThird {
  13. return &cityConfigThird{}
  14. }
  15. func (*cityConfigThird) GetServerName() string {
  16. return "city-config"
  17. }
  18. // 统一抽象一个方法,方便管理
  19. func (this *cityConfigThird) httpRequest(ctx context.Context, path string, params interface{}, result interface{}, options ...httpclent.Option) error {
  20. return httpclent.HttpRequestAndDecode(ctx, this.GetServerName(), path, params, result, options...)
  21. }
  22. // 获取城市信息
  23. func (this *cityConfigThird) CityInfo(ctx context.Context, params *dto.CityInfoParams) (*dto.CityInfoResponse, cerror.Cerror) {
  24. path := "/city-config/city/info"
  25. response := new(dto.CityInfoResponse)
  26. err := this.httpRequest(ctx, path, params, response, httpclent.CloseRetry)
  27. if err != nil {
  28. // 三方日志要打印warn日志,如果必要的话才打印error日志
  29. logger.Warnc(ctx, "[CityInfo] request err,params=%+v,err=%v", params, err)
  30. return nil, exception.CityInfoError(err)
  31. }
  32. return response, nil
  33. }