From e2d37cd02ef07d42db2cec4418df59d5f3ca6890 Mon Sep 17 00:00:00 2001 From: dustoair <107600816+dustoair@users.noreply.github.com> Date: Sat, 17 Sep 2022 18:57:58 +0800 Subject: [PATCH] reverse slice --- api/binancePrice.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/api/binancePrice.go b/api/binancePrice.go index 1f71ee2..e7363b2 100644 --- a/api/binancePrice.go +++ b/api/binancePrice.go @@ -27,9 +27,18 @@ func GetBinanceLatestPrice(symbol string) float64 { func GetBinanceLatestPrices(symbol string) []BinancePrice { var binancePrices []BinancePrice - global.DB.Where("symbol = ? ", symbol).Order("id desc").Find(&binancePrices) + //global.DB.Where("symbol = ? ", symbol).Find(&binancePrices) + global.DB.Where("symbol = ? ", symbol).Order("id desc").Limit(500).Find(&binancePrices) //global.DB.Where("symbol = ? order by id desc", symbol).Limit(30).Find(&binancePrices) - return binancePrices + reverseSlice := func(in []BinancePrice) []BinancePrice { + out := make([]BinancePrice, len(in)) + for i := range in { + out[i] = in[len(in)-1-i] + } + return out + } + return reverseSlice(binancePrices) + } func GetSerivers(symbol string) (timeUpdate []string, symbolPrice []float64) {