mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
no more reflection
This commit is contained in:
@@ -3,7 +3,6 @@ package console
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Console Command interface
|
||||
@@ -16,22 +15,6 @@ type Commander interface {
|
||||
defaults() error // set defaults wherever necessary
|
||||
}
|
||||
|
||||
// Set command fields based on indexes defined in default()
|
||||
func CmdRpcPrmsFromArgs(rpcPrms interface{}, args []string, idxArgsToRpcPrms map[int]string) {
|
||||
for idx := range args {
|
||||
fldName, hasIdx := idxArgsToRpcPrms[idx]
|
||||
if !hasIdx {
|
||||
continue
|
||||
}
|
||||
// field defined to be set by os.Args index
|
||||
if fld := reflect.ValueOf(rpcPrms).Elem().FieldByName(fldName); fld.Kind() == reflect.String {
|
||||
fld.SetString(args[idx])
|
||||
} else if fld.Kind() == reflect.Int {
|
||||
fld.SetInt(1) // Placeholder for future usage of data types other than strings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process args and return right command Value or error
|
||||
func GetCommandValue(args []string) (Commander, error) {
|
||||
if len(args) < 2 {
|
||||
|
||||
Reference in New Issue
Block a user