Skip to content

Instantly share code, notes, and snippets.

@wilk
Last active November 10, 2017 21:20
Show Gist options
  • Save wilk/ebe5353f4bea540f4138993eb654ad73 to your computer and use it in GitHub Desktop.
Save wilk/ebe5353f4bea540f4138993eb654ad73 to your computer and use it in GitHub Desktop.
Goxfer
import (
"fmt"
"strconv"
"sync"
)
type Transaction struct {
Date string
Account string
Description string
Amount float64
Tags []string
}
func addTransaction(transaction Transaction, token string) error {
// @todo: TBD
}
func main() {
fmt.Println("Pushing transactions on Buxfer...")
transactionAddedCounter := 0
transactionNotAddedCounter := 0
wg := &sync.WaitGroup{}
for index, bulk := range bulks {
fmt.Println("Pushing bulk #", index)
wg.Add(len(bulk))
for _, transaction := range bulk {
// going parallel
go func(transaction Transaction) {
fmt.Println("Pushing transaction:", transaction)
if err := addTransaction(transaction, token); err != nil {
transactionNotAddedCounter++
fmt.Println(err)
} else {
transactionAddedCounter++
}
wg.Done()
}(transaction)
}
// wait the end of each request of the current bulk
wg.Wait()
}
fmt.Println("Transactions succeded #", strconv.Itoa(transactionAddedCounter))
fmt.Println("Transactions failed #", strconv.Itoa(transactionNotAddedCounter))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment