goFieldPath builds a dot-separated Go field name for nested fields. For top-level fields it returns just the field name. For nested fields it reconstructs the parent struct field name from the prefix by looking at the enclosing type's fields.
(prefix, name string, _ reflect.Type, fullJSONName string)
| 168 | // fields it reconstructs the parent struct field name from the prefix |
| 169 | // by looking at the enclosing type's fields. |
| 170 | func goFieldPath(prefix, name string, _ reflect.Type, fullJSONName string) string { |
| 171 | if prefix == "" { |
| 172 | return name |
| 173 | } |
| 174 | // Build the Go path by walking the JSON name segments. Each |
| 175 | // segment maps to a struct field that we already traversed |
| 176 | // during recursion, so we reconstruct the path from the JSON |
| 177 | // parts. The parent extractFields call sets the prefix to the |
| 178 | // parent json name, so we can derive the Go path from the |
| 179 | // json segments by title-casing each part. |
| 180 | parts := strings.Split(fullJSONName, ".") |
| 181 | goNames := make([]string, 0, len(parts)) |
| 182 | for _, p := range parts { |
| 183 | goNames = append(goNames, jsonSegmentToGoName(p)) |
| 184 | } |
| 185 | return strings.Join(goNames, ".") |
| 186 | } |
| 187 | |
| 188 | // jsonSegmentToGoName converts a snake_case JSON segment to a |
| 189 | // PascalCase Go field name using common conventions. |
no test coverage detected