(typeOf reflect.Type)
| 156 | } |
| 157 | |
| 158 | func (t *TypeScriptify) deepFields(typeOf reflect.Type) []reflect.StructField { |
| 159 | fields := make([]reflect.StructField, 0) |
| 160 | |
| 161 | if typeOf.Kind() == reflect.Ptr { |
| 162 | typeOf = typeOf.Elem() |
| 163 | } |
| 164 | |
| 165 | if typeOf.Kind() != reflect.Struct { |
| 166 | return fields |
| 167 | } |
| 168 | |
| 169 | for i := 0; i < typeOf.NumField(); i++ { |
| 170 | f := typeOf.Field(i) |
| 171 | kind := f.Type.Kind() |
| 172 | isPointer := kind == reflect.Ptr && f.Type.Elem().Kind() == reflect.Struct |
| 173 | if f.Anonymous && kind == reflect.Struct { |
| 174 | // fmt.Println(v.Interface()) |
| 175 | fields = append(fields, t.deepFields(f.Type)...) |
| 176 | } else if f.Anonymous && isPointer { |
| 177 | // fmt.Println(v.Interface()) |
| 178 | fields = append(fields, t.deepFields(f.Type.Elem())...) |
| 179 | } else { |
| 180 | // Check we have a json tag |
| 181 | jsonTag := t.getJSONFieldName(f, isPointer) |
| 182 | if jsonTag != "" { |
| 183 | fields = append(fields, f) |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | return fields |
| 189 | } |
| 190 | |
| 191 | func (ts TypeScriptify) logf(depth int, s string, args ...interface{}) { |
| 192 | fmt.Printf(strings.Repeat(" ", depth)+s+"\n", args...) |
no test coverage detected