1
0
Fork 0

Use of Viper and cobra

This commit is contained in:
emile 2016-01-13 22:46:44 +01:00
parent a0b15a0efd
commit 35070f7c1c
No known key found for this signature in database
GPG key ID: D808B4C167352E59
32 changed files with 414 additions and 143 deletions

23
utils.go Normal file
View 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)
}