added structToSlice() so we can iterate structs

This commit is contained in:
2020-04-02 22:44:09 +00:00
parent 145239c39e
commit 95dc451ab3

View File

@ -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
}