You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
703 B
27 lines
703 B
package changekeys
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"git.aiterp.net/rpdata/api/models"
|
|
)
|
|
|
|
// Many returns a key set matching the input objects, but without the asterisk key. You may pass
|
|
// a slice as an argument, for example (log, posts) and it will be flattened
|
|
func Many(objects ...interface{}) []models.ChangeKey {
|
|
keys := make([]models.ChangeKey, 0, len(objects))
|
|
for _, object := range objects {
|
|
if v := reflect.ValueOf(object); v.Kind() == reflect.Slice {
|
|
elems := make([]interface{}, 0, v.Len())
|
|
for i := 0; i < v.Len(); i++ {
|
|
elems = append(elems, v.Index(i).Interface())
|
|
}
|
|
|
|
keys = append(keys, Many(elems...)...)
|
|
} else {
|
|
keys = append(keys, One(object))
|
|
}
|
|
}
|
|
|
|
return keys
|
|
}
|