|
1 | 1 | package instruct |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "errors" |
4 | 5 | "fmt" |
| 6 | + "io" |
5 | 7 | "reflect" |
6 | 8 | "strings" |
7 | 9 | ) |
@@ -45,6 +47,35 @@ func (s *structInfo) fieldByName(name string) *structInfo { |
45 | 47 | return nil |
46 | 48 | } |
47 | 49 |
|
| 50 | +func (s *structInfo) dump(w io.Writer) error { |
| 51 | + return s.dumpIndent("", w) |
| 52 | +} |
| 53 | + |
| 54 | +func (s *structInfo) dumpIndent(indent string, w io.Writer) error { |
| 55 | + var ferr error |
| 56 | + var err error |
| 57 | + _, err = fmt.Fprintf(w, "%s- ", indent) |
| 58 | + ferr = errors.Join(ferr, err) |
| 59 | + name := "{ROOT}" |
| 60 | + if s.field.Type != nil { |
| 61 | + name = s.field.Name |
| 62 | + } |
| 63 | + _, err = fmt.Fprintf(w, "%s [/%s] (type: %s, kind: %s) ", name, strings.Join(s.path, "/"), s.typ.Name(), s.typ.Kind().String()) |
| 64 | + ferr = errors.Join(ferr, err) |
| 65 | + if s.field.Type != nil { |
| 66 | + _, err = fmt.Fprintf(w, "[field type: %s, kind: %s] ", s.field.Type.String(), s.field.Type.Kind().String()) |
| 67 | + ferr = errors.Join(ferr, err) |
| 68 | + // _, err = fmt.Fprintf(w, "[path: '%s']", strings.Join(s.path, "/")) |
| 69 | + // ferr = errors.Join(ferr, err) |
| 70 | + } |
| 71 | + _, err = fmt.Fprintf(w, "\n") |
| 72 | + ferr = errors.Join(ferr, err) |
| 73 | + for _, field := range s.fields { |
| 74 | + ferr = errors.Join(ferr, field.dumpIndent(indent+"\t", w)) |
| 75 | + } |
| 76 | + return err |
| 77 | +} |
| 78 | + |
48 | 79 | // structInfoWithMapTags overrides a structInfo with a MapTags. This creates a clone of all the objects and don't |
49 | 80 | // change the original in any way. |
50 | 81 | func structInfoWithMapTags[IT any, DC DecodeContext](si *structInfo, mapTags MapTags, options DefaultOptions[IT, DC]) (*structInfo, error) { |
|
0 commit comments