Here is a peace of my code:
candles := make([]*base.OHLCVItem, 100)
for i, item := range msgStrSl {
newCandle, err := parseCandleFromString(item)
newCandle.Pair = pair
newCandle.Timeframe = timeframe
if err != nil {
bWsLog.WithError(err).Errorf("Failed to parse candle %d.", i)
continue
}
if newCandle == nil {
panic("nil candle")
}
candles = append(candles, newCandle)
bWsLog.Infof("Sn candle: %d", candles[len(candles)-1].Timestamp)
}
bWsLog.Info(candles[0])
bWsLog.Info(candles[1])
sort.SliceStable(candles, func(i, j int) bool {
bWsLog.Infof("%d %+v %+v", len(candles), candles[i], candles[j])
return candles[i].Timestamp < candles[j].Timestamp
}
Logs after the loop say that value is nil. But log inside the loop prints the object (so it is not a nil at that point) I'm new to Go and I can figure out why all the elements in slice became nil after the loop finishes. Could you help me with this issue please?