This commit is contained in:
邹宗楠
2023-09-06 13:50:39 +08:00
parent c207268323
commit 56588c5738
13 changed files with 177 additions and 11 deletions

View File

@@ -119,6 +119,10 @@ type API struct {
key string
}
func (a *API) SetKey(key string) {
a.key = key
}
type BuildingOrNeighborInfo struct {
Name string `json:"name"`
Type string `json:"type"`
@@ -278,6 +282,35 @@ func (a *API) AccessAPI(apiStr string, params map[string]interface{}) (retVal Re
return retVal, err
}
func (a *API) AccessAPI3(apiStr string, params map[string]interface{}) (retVal ResponseResult, err error) {
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
request, _ := http.NewRequest(http.MethodGet, utils.GenerateGetURL(BaseUrl, apiStr, params), nil)
return request
},
a.config,
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
if jsonResult1 == nil {
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
}
status := jsonResult1["status"].(string)
if status == StatusCodeSuccess {
retVal = jsonResult1
return platformapi.ErrLevelSuccess, nil
}
infoCode := jsonResult1["infocode"].(string)
newErr := utils.NewErrorCode(jsonResult1["info"].(string), infoCode)
if _, ok := exceedLimitCodes[infoCode]; ok {
return platformapi.ErrLevelExceedLimit, newErr
} else if _, ok := canRetryCodes[infoCode]; ok {
return platformapi.ErrLevelRecoverableErr, newErr
} else {
return platformapi.ErrLevelCodeIsNotOK, newErr
}
})
return retVal, err
}
func (a *API) BatchAccessAPI(apiList []*tBatchAPIParams) (retVal []*tBatchAPIResponse, err error) {
if len(apiList) == 0 {
return nil, nil