From 2c1b96c6b3f708cba7d02e966a90f3f098ca6eb5 Mon Sep 17 00:00:00 2001 From: DanB Date: Tue, 14 Jan 2014 17:23:53 +0100 Subject: [PATCH] Console AddBalance with Weight --- apier/v1/apier.go | 4 +++- console/add_balance.go | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 0fb805ece..a944ebb30 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -93,6 +93,7 @@ type AttrAddBalance struct { BalanceId string Direction string Value float64 + Weight float64 Overwrite bool // When true it will reset if the balance is already there } @@ -119,7 +120,8 @@ func (self *ApierV1) AddBalance(attr *AttrAddBalance, reply *string) error { if attr.Overwrite { aType = engine.TOPUP_RESET } - at.SetActions(engine.Actions{&engine.Action{ActionType: aType, BalanceId: attr.BalanceId, Direction: attr.Direction, Balance: &engine.Balance{Value: attr.Value}}}) + at.SetActions(engine.Actions{&engine.Action{ActionType: aType, BalanceId: attr.BalanceId, Direction: attr.Direction, + Balance: &engine.Balance{Value: attr.Value, Weight: attr.Weight}}}) if err := at.Execute(); err != nil { *reply = err.Error() return err diff --git a/console/add_balance.go b/console/add_balance.go index 4bf430cd0..ba2348837 100644 --- a/console/add_balance.go +++ b/console/add_balance.go @@ -38,7 +38,7 @@ type CmdAddBalance struct { // name should be exec's name func (self *CmdAddBalance) Usage(name string) string { - return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] add_balance [ [ [overwrite]]]") + return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] add_balance [ [ [overwrite]]]") } // set param defaults @@ -51,6 +51,7 @@ func (self *CmdAddBalance) defaults() error { // Parses command line args and builds CmdBalance value func (self *CmdAddBalance) FromArgs(args []string) error { + var err error if len(args) < 5 { return fmt.Errorf(self.Usage("")) } @@ -67,7 +68,9 @@ func (self *CmdAddBalance) FromArgs(args []string) error { self.rpcParams.BalanceId = args[5] } if len(args) > 6 { - self.rpcParams.Direction = args[6] + if self.rpcParams.Weight, err = strconv.ParseFloat(args[6], 64); err != nil { + return fmt.Errorf("Cannot parse weight parameter") + } } if len(args) > 7 { if args[7] == "overwrite" {