Created
November 8, 2017 19:58
-
-
Save wilk/e6dcaf7493a356892dd71279f5dd0700 to your computer and use it in GitHub Desktop.
Goxfer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strconv" | |
"gopkg.in/mgo.v2" | |
) | |
type Transaction struct { | |
Date string | |
Account string | |
Description string | |
Amount float64 | |
Tags []string | |
} | |
var ( | |
BULK_LEN, _ = strconv.Atoi(os.Getenv("BULK_LENGHT")) | |
) | |
func main() { | |
fmt.Println("Fetching transactions from DB...") | |
results := []Transaction{} | |
err = collected.Find(nil).All(&results) | |
if err != nil { | |
panic(err) | |
} | |
bulks := [][]Transaction{} | |
counter := 0 | |
iterations := len(results) / BULK_LEN | |
for i := 0; i < iterations; i++ { | |
bulks = append(bulks, results[counter:counter + BULK_LEN]) | |
counter += BULK_LEN | |
} | |
if counter < iterations { | |
bulks = append(bulks, results[counter:iterations - counter]) | |
} | |
fmt.Println("Transactions fetched and divided into small bulk of #", strconv.Itoa(BULK_LEN), "transactions") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment