Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfeng-db committed Aug 19, 2024
1 parent de0818f commit 6a42ca3
Show file tree
Hide file tree
Showing 8 changed files with 1,655 additions and 18 deletions.
8 changes: 4 additions & 4 deletions common/force_send_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ func SetForceSendFields(req any, d attributeGetter, fields []string) {
if !ok {
panic(fmt.Errorf("request argument to setForceSendFields must have ForceSendFields field of type []string (got %s)", forceSendFieldsField.Type()))
}
fs := listAllFields(rv)
fs := ListAllFields(rv)
for _, fieldName := range fields {
found := false
var structField reflect.StructField
for _, f := range fs {
fn := chooseFieldName(f.sf)
fn := chooseFieldName(f.Sf)
if fn != "-" && fn == fieldName {
found = true
structField = f.sf
structField = f.Sf
break
}
}
if !found {
allFieldNames := make([]string, 0)
for _, f := range fs {
fn := chooseFieldName(f.sf)
fn := chooseFieldName(f.Sf)
if fn == "-" || fn == "force_send_fields" {
continue
}
Expand Down
28 changes: 14 additions & 14 deletions common/reflect_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,22 @@ func diffSuppressor(fieldName string, v *schema.Schema) func(k, old, new string,
}
}

type field struct {
sf reflect.StructField
v reflect.Value
type Field struct {
Sf reflect.StructField
V reflect.Value
}

func listAllFields(v reflect.Value) []field {
func ListAllFields(v reflect.Value) []Field {
t := v.Type()
fields := make([]field, 0, v.NumField())
fields := make([]Field, 0, v.NumField())
for i := 0; i < v.NumField(); i++ {
f := t.Field(i)
if f.Anonymous {
fields = append(fields, listAllFields(v.Field(i))...)
fields = append(fields, ListAllFields(v.Field(i))...)
} else {
fields = append(fields, field{
sf: f,
v: v.Field(i),
fields = append(fields, Field{
Sf: f,
V: v.Field(i),
})
}
}
Expand All @@ -418,9 +418,9 @@ func typeToSchema(v reflect.Value, aliases map[string]map[string]string, tc trac
panic(fmt.Errorf("Schema value of Struct is expected, but got %s: %#v", reflectKind(rk), v))
}
tc = tc.visit(v)
fields := listAllFields(v)
fields := ListAllFields(v)
for _, field := range fields {
typeField := field.sf
typeField := field.Sf
if tc.depthExceeded(typeField) {
// Skip the field if recursion depth is over the limit.
log.Printf("[TRACE] over recursion limit, skipping field: %s, max depth: %d", getNameForType(typeField.Type), tc.getMaxDepthForTypeField(typeField))
Expand Down Expand Up @@ -597,9 +597,9 @@ func iterFields(rv reflect.Value, path []string, s map[string]*schema.Schema, al
return fmt.Errorf("%s: got invalid reflect value %#v", path, rv)
}
isGoSDK := isGoSdk(rv)
fields := listAllFields(rv)
fields := ListAllFields(rv)
for _, field := range fields {
typeField := field.sf
typeField := field.Sf
fieldName := chooseFieldNameWithAliases(typeField, rv.Type(), aliases)
if fieldName == "-" {
continue
Expand All @@ -617,7 +617,7 @@ func iterFields(rv reflect.Value, path []string, s map[string]*schema.Schema, al
if !isGoSDK && fieldSchema.Optional && defaultEmpty && !omitEmpty {
return fmt.Errorf("inconsistency: %s is optional, default is empty, but has no omitempty", fieldName)
}
valueField := field.v
valueField := field.V
err := cb(fieldSchema, append(path, fieldName), &valueField)
if err != nil {
return fmt.Errorf("%s: %s", fieldName, err)
Expand Down
Loading

0 comments on commit 6a42ca3

Please sign in to comment.