如何阅读要附加的切片?

I want to read a slice and append new data to it. I had a webapi in json format to read the statistics. So I want to grab the statistic, give it to a function, write a new slice with the existing stats from the json before.

Then I want to append new data at the end of it. And give the "new" Slice (Struct) with the old statistics from the json and the new together.

I tried so much, that's it.

This is the json looks like

{"24hreward":0,"currentHashrate":0,"hashrate":0,"history":[{"currenthashrate":6024360000,"online":0,"offline":0,"timestamp":0}],"pageSize":30,"payments":null,"paymentsTotal":0,"rewards":[{"blockheight":223115,"timestamp":1518179084,"blockhash":"0x*************ee03802ee52f411102159a7c9268fec4e46571daa07e84","reward":6024360000,"percent":1,"immature":false}],"roundShares":3674,"stats":{"balance":6024360000,"blocksFound":1,"immature":0,"lastShare":1518208862},"sumrewards":[{"inverval":3600,"reward":0,"name":"Last 60 minutes","offset":0},{"inverval":43200,"reward":0,"name":"Last 12 hours","offset":0},{"inverval":86400,"reward":0,"name":"Last 24 hours","offset":0},{"inverval":604800,"reward":0,"name":"Last 7 days","offset":0},{"inverval":2592000,"reward":6024360000,"name":"Last 30 days","offset":0}],"workers":{},"workersOffline":0,"workersOnline":0,"workersTotal":0}

That's the struct

type HistoryData struct {
    CurrentHashrate     int64    `json:"currenthashrate"`
    Online              int64    `json:"online"`
    Offline             int64    `json:"offline"`
    Timestamp           int64    `json:"timestamp"`
}

There you can see "history". I want to read the history and give it to my function here

cmds, err := tx.Exec(func() error {
    tx.ZRemRangeByScore(r.formatKey("hashrate", login), "-inf", fmt.Sprint("(", now-largeWindow))
    tx.ZRangeWithScores(r.formatKey("hashrate", login), 0, -1)
    tx.LRange(r.formatKey("lastshares"), 0, 4999)
    tx.ZRevRangeWithScores(r.formatKey("rewards", login), 0, 39)
    tx.ZRevRangeWithScores(r.formatKey("rewards", login), 0, -1)
    tx.ZRevRangeWithScores(r.formatKey("history", login), 0, 64)
    return nil
})

stats["history"] = convertHistoryResults(currentHashrate, online, offline, now, cmds[5].(*redis.ZSliceCmd))

There I want to give in convertHistoryResults "currentHashrate, online, offline, now" and cmds[5] from top but there is nothing. The json shows data but he cannot read i think :/ Thats my Problem And here the function convertHistoryResults to build the list for the "history" in the json

var count = 0;
func convertHistoryResults(currenthashrate int64, online int64, offline int64, now int64, rows ...*redis.ZSliceCmd) []*HistoryData {
    var result []*HistoryData
    log.Println("run1")
    log.Println(count)
    log.Println(rows)
    history := HistoryData{}
    for _, row := range rows {
        for _, v := range row.Val() {
                log.Println("run3")
                fields := strings.Split(v.Member.(string), ":")
                history.CurrentHashrate, _ = strconv.ParseInt(fields[0], 10, 64)
                history.Online, _ = strconv.ParseInt(fields[1], 10, 64)
                history.Offline, _ = strconv.ParseInt(fields[2], 10, 64)
                history.Timestamp, _ = strconv.ParseInt(fields[3], 10, 64)
                result = append(result, &history)
        }
    }
    if(count > 0) { // Count = 40 ~4-6min
        history.CurrentHashrate = currenthashrate


    history.Online = online
    history.Offline = offline
    history.Timestamp = now
    result = append(result, &history)
    log.Println("run2")
    //if len(result) > 300 {
    //    result = result[1:]
    //}
    count = 0;
} else {
    log.Println("run4")
    count++
}
return result
}

Here I build new HistoryData and want to read the "old" rows and append them to the HistoryData, than i want to give the new Data into it with count, cause i dont want this all seconds.

But my Problem is I cannot read the old "history" from the json but I don't know why. With "rewards" its working. Its a code from https://github.com/sammy007/open-ethereum-pool

What i tried is, to read the "history" and give them to convertHistoryResults to build new History to append that to "history".

Hope someone can help me to get the old "history" and rebuild to new "history"

This script is running from much different users, so I must rebuild the "history" for each one running it.

That is the print in log

[ZREVRANGE miner:history:0x******************** 0 64 WITHSCORES: []]

You see, WITHSCORES is []

I also tried in for Rewards, thats like that

[ZREVRANGE miner:rewards:0x******************** 0 64 WITHSCORES: [{1.518179084e+09 6024360000:1.000000000:0:0x**********************159a7c9268fec4e46571daa07e84:223115:1518179084}]]