( fldDescs []pgconn.FieldDescription, t reflect.Type, fields []structRowField, fieldStack *[]int, )
| 772 | } |
| 773 | |
| 774 | func computeNamedStructFields( |
| 775 | fldDescs []pgconn.FieldDescription, |
| 776 | t reflect.Type, |
| 777 | fields []structRowField, |
| 778 | fieldStack *[]int, |
| 779 | ) ([]structRowField, string) { |
| 780 | var missingField string |
| 781 | tail := len(*fieldStack) |
| 782 | *fieldStack = append(*fieldStack, 0) |
| 783 | for i := 0; i < t.NumField(); i++ { |
| 784 | sf := t.Field(i) |
| 785 | (*fieldStack)[tail] = i |
| 786 | if sf.PkgPath != "" && !sf.Anonymous { |
| 787 | // Field is unexported, skip it. |
| 788 | continue |
| 789 | } |
| 790 | // Handle anonymous struct embedding, but do not try to handle embedded pointers. |
| 791 | if sf.Anonymous && sf.Type.Kind() == reflect.Struct { |
| 792 | var missingSubField string |
| 793 | fields, missingSubField = computeNamedStructFields( |
| 794 | fldDescs, |
| 795 | sf.Type, |
| 796 | fields, |
| 797 | fieldStack, |
| 798 | ) |
| 799 | if missingField == "" { |
| 800 | missingField = missingSubField |
| 801 | } |
| 802 | } else { |
| 803 | dbTag, dbTagPresent := sf.Tag.Lookup(structTagKey) |
| 804 | if dbTagPresent { |
| 805 | dbTag, _, _ = strings.Cut(dbTag, ",") |
| 806 | } |
| 807 | if dbTag == "-" { |
| 808 | // Field is ignored, skip it. |
| 809 | continue |
| 810 | } |
| 811 | colName := dbTag |
| 812 | if !dbTagPresent { |
| 813 | colName = sf.Name |
| 814 | } |
| 815 | fpos := fieldPosByName(fldDescs, colName, !dbTagPresent) |
| 816 | if fpos == -1 { |
| 817 | if missingField == "" { |
| 818 | missingField = colName |
| 819 | } |
| 820 | continue |
| 821 | } |
| 822 | fields[fpos] = structRowField{ |
| 823 | path: append([]int(nil), *fieldStack...), |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | *fieldStack = (*fieldStack)[:tail] |
| 828 | |
| 829 | return fields, missingField |
| 830 | } |
| 831 |
no test coverage detected