c74fcbf282
Since caching all subject data proved too complex in the time available, this implementation uses a simple key/value lookup table to cache subject names and perform backward searches by uid.
38 lines
626 B
Go
38 lines
626 B
Go
package entity
|
|
|
|
import (
|
|
"reflect"
|
|
)
|
|
|
|
// Values is a shortcut for map[string]interface{}
|
|
type Values map[string]interface{}
|
|
|
|
// GetValues extracts entity Values.
|
|
func GetValues(m interface{}, omit ...string) (result Values) {
|
|
skip := func(name string) bool {
|
|
for _, s := range omit {
|
|
if name == s {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
result = make(map[string]interface{})
|
|
|
|
elem := reflect.ValueOf(m).Elem()
|
|
relType := elem.Type()
|
|
|
|
for i := 0; i < relType.NumField(); i++ {
|
|
name := relType.Field(i).Name
|
|
|
|
if skip(name) {
|
|
continue
|
|
}
|
|
|
|
result[name] = elem.Field(i).Interface()
|
|
}
|
|
|
|
return result
|
|
}
|