Skip to content

Commit

Permalink
update defer
Browse files Browse the repository at this point in the history
  • Loading branch information
cherry-yl-sh committed Jun 20, 2024
1 parent f3c7197 commit 56eb30a
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions common/price_compoent/price_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,14 @@ func GetPriceUsd(tokenType global_const.TokenType) (float64, error) {

}

defer func(Body io.ReadCloser) {
if p := recover(); p != nil {
logrus.Error("panic: ", p)
return
}
if Body == nil {
return
}
err := Body.Close()
if err != nil {
logrus.Error("close body error: ", err)
return
}
}(res.Body)
body, _ := io.ReadAll(res.Body)
bodystr := string(body)
strarr := strings.Split(bodystr, ":")
usdstr := strings.TrimRight(strarr[2], "}}")
err := res.Body.Close()
if err != nil {
logrus.Errorf("close body error: %v", err)
}
return strconv.ParseFloat(usdstr, 64)
}

Expand Down

0 comments on commit 56eb30a

Please sign in to comment.