Skip to content

Commit 8d834e2

Browse files
committed
go: 경매장 아이템 평균가 계산 시 수집된 통계가 없을 시 패닉이 발생할 수 있는 문제 수정
stats가 빈 배열이면 calculateAveragePrice 메서드에서 0으로 나눗셈을 시도하기 때문에 패닉이 발생할 수 있어 얼리리턴을 추가함.
1 parent dc575b4 commit 8d834e2

File tree

1 file changed

+4
-0
lines changed
  • src/go/apps/auction-item-stat-scraper/converter

1 file changed

+4
-0
lines changed

src/go/apps/auction-item-stat-scraper/converter/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
)
77

88
func calculateAveragePrice(stats []loadb.AuctionItemStat) decimal.Decimal {
9+
if len(stats) == 0 {
10+
return decimal.NewFromInt(0)
11+
}
12+
913
totalPrice := decimal.NewFromInt(0)
1014
for _, stat := range stats {
1115
totalPrice = totalPrice.Add(decimal.NewFromInt(int64(stat.BuyPrice)))

0 commit comments

Comments
 (0)