Use of Viper and cobra
This commit is contained in:
parent
a0b15a0efd
commit
35070f7c1c
32 changed files with 414 additions and 143 deletions
23
utils.go
Normal file
23
utils.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
Copyright
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Invoke calls the specified method with the specified arguments on the specified interface.
|
||||
// It uses the go(lang) reflect package.
|
||||
func invoke(any interface{}, name string, args ...interface{}) ([]reflect.Value, error) {
|
||||
inputs := make([]reflect.Value, len(args))
|
||||
for i := range args {
|
||||
inputs[i] = reflect.ValueOf(args[i])
|
||||
}
|
||||
method := reflect.ValueOf(any).MethodByName(name)
|
||||
if method.IsValid() {
|
||||
return method.Call(inputs), nil
|
||||
}
|
||||
return nil, errors.New("Method not found: " + name)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue