123456789101112131415161718192021222324252627282930313233343536 |
- package db
- import (
- "reflect"
- )
- func StructPointers(s interface{}) []interface{} {
- model := reflect.ValueOf(s)
- modelElem := model.Elem()
- numFields := modelElem.NumField()
- var Ptrs []interface{}
- for i := 0; i < numFields; i++ {
- field := modelElem.Field(i)
- tag := modelElem.Type().Field(i).Tag
- if tag != "" {
- continue
- }
- // Merge
- if field.Kind() == reflect.Struct {
- Ptrs = append(Ptrs, StructPointers(field.Addr().Interface())...)
- continue
- }
- Ptrs = append(Ptrs, field.Addr().Interface())
- }
- return Ptrs
- }
|