DumpInfo Useful function for debugging purposes - to see what's in the struct at runtime
(tbl DynamicTabler)
| 136 | |
| 137 | // DumpInfo Useful function for debugging purposes - to see what's in the struct at runtime |
| 138 | func DumpInfo(tbl DynamicTabler) map[string]any { |
| 139 | typ := reflect.TypeOf(tbl.Unwrap()) |
| 140 | type typeInfo struct { |
| 141 | Type string |
| 142 | Tags string |
| 143 | } |
| 144 | var fn func(t reflect.Type) map[string]any |
| 145 | fn = func(t reflect.Type) map[string]any { |
| 146 | infoMap := map[string]any{} |
| 147 | if t.Kind() == reflect.Pointer { |
| 148 | t = t.Elem() |
| 149 | } |
| 150 | if t.Kind() != reflect.Struct { |
| 151 | return infoMap |
| 152 | } |
| 153 | for i := 0; i < t.NumField(); i++ { |
| 154 | f := t.Field(i) |
| 155 | if f.Anonymous { |
| 156 | subMap := fn(f.Type) |
| 157 | infoMap[f.Name] = subMap |
| 158 | } else { |
| 159 | if t.Kind() == reflect.Pointer { |
| 160 | t = t.Elem() |
| 161 | } |
| 162 | if t.Kind() == reflect.Struct { |
| 163 | subMap := fn(f.Type) |
| 164 | if len(subMap) == 0 { |
| 165 | infoMap[f.Name] = typeInfo{ |
| 166 | Type: f.Type.Name(), |
| 167 | Tags: string(f.Tag), |
| 168 | } |
| 169 | } else { |
| 170 | infoMap[f.Name] = subMap |
| 171 | } |
| 172 | } else { |
| 173 | infoMap[f.Name] = typeInfo{ |
| 174 | Type: f.Type.Name(), |
| 175 | Tags: string(f.Tag), |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | return infoMap |
| 181 | } |
| 182 | return fn(typ) |
| 183 | } |