add struct to map
This commit is contained in:
parent
3873486b30
commit
2f4bd7faf2
14
libs/flag.go
14
libs/flag.go
@ -2,6 +2,7 @@ package libs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flags - flag values struct
|
// Flags - flag values struct
|
||||||
@ -27,3 +28,16 @@ func RegFlag(f *Flags) {
|
|||||||
flag.BoolVar(&f.Override, "y", false, "if output file exists override")
|
flag.BoolVar(&f.Override, "y", false, "if output file exists override")
|
||||||
flag.StringVar(&f.Password, "p", "", "private key password")
|
flag.StringVar(&f.Password, "p", "", "private key password")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Flags) ToMap() map[string]interface{} {
|
||||||
|
t := reflect.ValueOf(f).Elem()
|
||||||
|
|
||||||
|
smap := make(map[string]interface{})
|
||||||
|
|
||||||
|
for i := 0; i < t.NumField(); i++ {
|
||||||
|
f := t.Field(i)
|
||||||
|
smap[t.Type().Field(i).Name] = f.Interface()
|
||||||
|
}
|
||||||
|
|
||||||
|
return smap
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user