util.go 546 B

123456789101112131415161718192021222324252627282930313233343536
  1. package db
  2. import (
  3. "reflect"
  4. )
  5. func StructPointers(s interface{}) []interface{} {
  6. model := reflect.ValueOf(s)
  7. modelElem := model.Elem()
  8. numFields := modelElem.NumField()
  9. var Ptrs []interface{}
  10. for i := 0; i < numFields; i++ {
  11. field := modelElem.Field(i)
  12. tag := modelElem.Type().Field(i).Tag
  13. if tag != "" {
  14. continue
  15. }
  16. // Merge
  17. if field.Kind() == reflect.Struct {
  18. Ptrs = append(Ptrs, StructPointers(field.Addr().Interface())...)
  19. continue
  20. }
  21. Ptrs = append(Ptrs, field.Addr().Interface())
  22. }
  23. return Ptrs
  24. }