You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
554 B
36 lines
554 B
package cmd
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
)
|
|
|
|
func balance(args []string) error {
|
|
fs := flag.NewFlagSet("balance", flag.ExitOnError)
|
|
var userId int64
|
|
fs.Int64Var(&userId, "userId", 0, "Id of user (required)")
|
|
fs.Parse(args)
|
|
|
|
if userId <= 0 {
|
|
fs.Usage()
|
|
return fmt.Errorf("Missing userId")
|
|
}
|
|
|
|
tx, err := readDb()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
total := float64(0)
|
|
|
|
for _, r := range tx.Records {
|
|
if r.UserId == uint64(userId) {
|
|
total += r.Amount
|
|
}
|
|
}
|
|
fmt.Printf("UserId: %d\n", userId)
|
|
fmt.Printf("Balance: %f\n", total)
|
|
|
|
return nil
|
|
}
|