GraphQL API and utilities for the rpdata project
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

  1. package changekeys
  2. import (
  3. "reflect"
  4. "git.aiterp.net/rpdata/api/models"
  5. )
  6. // Many returns a key set matching the input objects, but without the asterisk key. You may pass
  7. // a slice as an argument, for example (log, posts) and it will be flattened
  8. func Many(objects ...interface{}) []models.ChangeKey {
  9. keys := make([]models.ChangeKey, 0, len(objects))
  10. for _, object := range objects {
  11. if v := reflect.ValueOf(object); v.Kind() == reflect.Slice {
  12. elems := make([]interface{}, 0, v.Len())
  13. for i := 0; i < v.Len(); i++ {
  14. elems = append(elems, v.Index(i).Interface())
  15. }
  16. keys = append(keys, Many(elems...)...)
  17. } else {
  18. keys = append(keys, One(object))
  19. }
  20. }
  21. return keys
  22. }