diff --git a/utils.go b/utils.go index b618b16..6dc02dd 100644 --- a/utils.go +++ b/utils.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "reflect" "strings" "samhofi.us/x/keybase/types/chat1" @@ -58,3 +59,14 @@ func isRootCommand(s string, baseCommand string, botName string) bool { } return false } + +// this converts structs to slices of (Name, Value) pairs +func structToSlice(v interface{}) []reflectStruct { + x := reflect.ValueOf(v) + values := make([]reflectStruct, x.NumField()) + for i := 0; i < x.NumField(); i++ { + values[i].Value = x.Field(i).Interface() + values[i].Name = x.Type().Field(i).Name + } + return values +}