From 1633048cd4843c970241fbc267a9351aa0f60198 Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 13 Sep 2012 09:32:41 +0200 Subject: [PATCH] Running go fmt on modified files --- cmd/cgr-console/cgr-console.go | 18 +++++++++--------- console/balance.go | 21 ++++++++++----------- console/command.go | 33 +++++++++++++++------------------ console/status.go | 8 ++++---- 4 files changed, 38 insertions(+), 42 deletions(-) diff --git a/cmd/cgr-console/cgr-console.go b/cmd/cgr-console/cgr-console.go index aaef47e5e..396047ddf 100644 --- a/cmd/cgr-console/cgr-console.go +++ b/cmd/cgr-console/cgr-console.go @@ -19,6 +19,7 @@ along with this program. If not, see package main import ( + "console" "flag" "fmt" "log" @@ -27,13 +28,12 @@ import ( "os" "reflect" "timespans" - "console" ) var ( - version = flag.Bool("version", false, "Prints the application version.") - server = flag.String("server", "127.0.0.1:2001", "server address host:port") - json = flag.Bool("json", true, "Use JSON for RPC encoding.") + version = flag.Bool("version", false, "Prints the application version.") + server = flag.String("server", "127.0.0.1:2001", "server address host:port") + json = flag.Bool("json", true, "Use JSON for RPC encoding.") ) func main() { @@ -55,16 +55,16 @@ func main() { } defer client.Close() // Strict command parsing starts here - args := append( []string{os.Args[0]}, flag.Args()... ) // Emulate os.Args by prepending the cmd to list of args coming from flag - cmd, cmdErr := console.GetCommandValue( args ) + args := append([]string{os.Args[0]}, flag.Args()...) // Emulate os.Args by prepending the cmd to list of args coming from flag + cmd, cmdErr := console.GetCommandValue(args) if cmdErr != nil { - log.Fatal( cmdErr ) + log.Fatal(cmdErr) } res := cmd.RpcResult() if rpcErr := client.Call(cmd.RpcMethod(), cmd.RpcParams(), res); rpcErr != nil { - log.Fatal( err ) + log.Fatal(err) } - fmt.Println( reflect.ValueOf(res).Elem().String() ) + fmt.Println(reflect.ValueOf(res).Elem().String()) } diff --git a/console/balance.go b/console/balance.go index caa631589..307331603 100644 --- a/console/balance.go +++ b/console/balance.go @@ -8,18 +8,17 @@ import ( "path/filepath" ) - -type PrmsGetBalance struct { - User string - BalanceType string - Direction string +type PrmsGetBalance struct { + User string + BalanceType string + Direction string } type CmdGetBalance struct { - rpcMethod string - rpcParams PrmsGetBalance - rpcResult string - idxArgsToRpcPrms map[int]string + rpcMethod string + rpcParams PrmsGetBalance + rpcResult string + idxArgsToRpcPrms map[int]string } // name should be exec's name @@ -44,11 +43,11 @@ func (self *CmdGetBalance) FromArgs(args []string) error { // Args look OK, set defaults before going further self.defaults() // Dynamically set rpc params - CmdRpcPrmsFromArgs( self.rpcParams, args, self.idxArgsToRpcPrms ) + CmdRpcPrmsFromArgs(self.rpcParams, args, self.idxArgsToRpcPrms) return nil } -func (self *CmdGetBalance) RpcMethod () string { +func (self *CmdGetBalance) RpcMethod() string { return self.rpcMethod } diff --git a/console/command.go b/console/command.go index 5489d7414..a647ec5de 100644 --- a/console/command.go +++ b/console/command.go @@ -1,26 +1,23 @@ package console - import ( "fmt" - "reflect" "path/filepath" + "reflect" ) - // Console Command interface type Commander interface { - FromArgs(args []string) error // Load data from os arguments or flag.Args() - Usage(string) string // usage message - RpcMethod() string // Method which should be called remotely - RpcParams() interface{} // Parameters to send out on rpc - RpcResult() interface{} // Only requirement is to have a String method to print on console - defaults() error // set default field values + FromArgs(args []string) error // Load data from os arguments or flag.Args() + Usage(string) string // usage message + RpcMethod() string // Method which should be called remotely + RpcParams() interface{} // Parameters to send out on rpc + RpcResult() interface{} // Only requirement is to have a String method to print on console + defaults() error // set default field values } - // Set command fields based on indexes defined in default() -func CmdRpcPrmsFromArgs( rpcPrms interface{}, args []string, idxArgsToRpcPrms map[int]string ) { +func CmdRpcPrmsFromArgs(rpcPrms interface{}, args []string, idxArgsToRpcPrms map[int]string) { for idx := range args { fldName, hasIdx := idxArgsToRpcPrms[idx] if !hasIdx { @@ -36,22 +33,22 @@ func CmdRpcPrmsFromArgs( rpcPrms interface{}, args []string, idxArgsToRpcPrms ma } // Process args and return right command Value or error -func GetCommandValue( args []string ) ( Commander, error ) { +func GetCommandValue(args []string) (Commander, error) { if len(args) < 2 { - return nil, fmt.Errorf( "usage: %s \n", filepath.Base(args[0]) ) - } - cmd := args[1] - var cmdVal Commander + return nil, fmt.Errorf("usage: %s \n", filepath.Base(args[0])) + } + cmd := args[1] + var cmdVal Commander switch cmd { case "status": cmdVal = &CmdStatus{} case "get_balance": cmdVal = &CmdGetBalance{} default: - return nil, fmt.Errorf( "usage: %s \n", filepath.Base(args[0]) ) + return nil, fmt.Errorf("usage: %s \n", filepath.Base(args[0])) } if err := cmdVal.FromArgs(args); err != nil { return nil, err - } + } return cmdVal, nil } diff --git a/console/status.go b/console/status.go index 593376913..fd43e96bc 100644 --- a/console/status.go +++ b/console/status.go @@ -5,9 +5,9 @@ import ( ) type CmdStatus struct { - rpcMethod string - rpcParams string - rpcResult string + rpcMethod string + rpcParams string + rpcResult string } func (self *CmdStatus) Usage(name string) string { @@ -24,7 +24,7 @@ func (self *CmdStatus) FromArgs(args []string) error { return nil } -func (self *CmdStatus) RpcMethod () string { +func (self *CmdStatus) RpcMethod() string { return self.rpcMethod }