Fixed bug with price slice size

This commit is contained in:
Artyom Belousov 2019-05-11 19:22:08 +03:00
parent c0f781fc7a
commit f7a703769f
2 changed files with 10 additions and 2 deletions

View file

@ -11,5 +11,5 @@ func main() {
rand.Seed(time.Now().UTC().UnixNano())
r := gin.Default()
r.POST("callback/message", vk.HandleMessage)
r.Run(":8000")
r.Run(":80")
}

View file

@ -8,6 +8,13 @@ import (
const CARDSLIMIT = 8
func min(a, b int) int {
if a < b {
return a
}
return b
}
func HandleMessage(c *gin.Context) {
var req MessageRequest
c.BindJSON(&req)
@ -24,7 +31,8 @@ func HandleMessage(c *gin.Context) {
Message(req.Object.UserId, "Карта не найдена")
} else {
prices, _ := cardsinfo.GetSCGPrices(cardName)
prices = prices[:CARDSLIMIT]
elements := min(CARDSLIMIT, len(prices))
prices = prices[:elements]
priceInfo := cardsinfo.FormatCardPrices(cardName, prices)
Message(req.Object.UserId, priceInfo)
}