helper/schema: clean up style

This commit is contained in:
Mitchell Hashimoto 2015-06-25 22:01:54 -07:00
parent 6e509aedcb
commit 0100d4139b
1 changed files with 35 additions and 65 deletions

View File

@ -842,76 +842,46 @@ func (m schemaMap) diffSet(
}) })
} }
removed := os.Difference(ns) // Build the list of codes that will make up our set. This is the
for _, code := range removed.listCode() { // removed codes as well as all the codes in the new codes.
// If the code is negative (first character is -) then codes := make([][]int, 2)
// replace it with "~" for our computed set stuff. codes[0] = os.Difference(ns).listCode()
codeStr := strconv.Itoa(code) codes[1] = ns.listCode()
if codeStr[0] == '-' { for _, list := range codes {
codeStr = string('~') + codeStr[1:] for _, code := range list {
} // If the code is negative (first character is -) then
// replace it with "~" for our computed set stuff.
codeStr := strconv.Itoa(code)
if codeStr[0] == '-' {
codeStr = string('~') + codeStr[1:]
}
switch t := schema.Elem.(type) { switch t := schema.Elem.(type) {
case *Resource: case *Resource:
// This is a complex resource // This is a complex resource
for k2, schema := range t.Schema { for k2, schema := range t.Schema {
subK := fmt.Sprintf("%s.%s.%s", k, codeStr, k2) subK := fmt.Sprintf("%s.%s.%s", k, codeStr, k2)
err := m.diff(subK, schema, diff, d, true) err := m.diff(subK, schema, diff, d, true)
if err != nil {
return err
}
}
case *Schema:
// Copy the schema so that we can set Computed/ForceNew from
// the parent schema (the TypeSet).
t2 := *t
t2.ForceNew = schema.ForceNew
// This is just a primitive element, so go through each and
// just diff each.
subK := fmt.Sprintf("%s.%s", k, codeStr)
err := m.diff(subK, &t2, diff, d, true)
if err != nil { if err != nil {
return err return err
} }
default:
return fmt.Errorf("%s: unknown element type (internal)", k)
} }
case *Schema:
// Copy the schema so that we can set Computed/ForceNew from
// the parent schema (the TypeSet).
t2 := *t
t2.ForceNew = schema.ForceNew
// This is just a primitive element, so go through each and
// just diff each.
subK := fmt.Sprintf("%s.%s", k, codeStr)
err := m.diff(subK, &t2, diff, d, true)
if err != nil {
return err
}
default:
return fmt.Errorf("%s: unknown element type (internal)", k)
}
}
for _, code := range ns.listCode() {
// If the code is negative (first character is -) then
// replace it with "~" for our computed set stuff.
codeStr := strconv.Itoa(code)
if codeStr[0] == '-' {
codeStr = string('~') + codeStr[1:]
}
switch t := schema.Elem.(type) {
case *Resource:
// This is a complex resource
for k2, schema := range t.Schema {
subK := fmt.Sprintf("%s.%s.%s", k, codeStr, k2)
err := m.diff(subK, schema, diff, d, true)
if err != nil {
return err
}
}
case *Schema:
// Copy the schema so that we can set Computed/ForceNew from
// the parent schema (the TypeSet).
t2 := *t
t2.ForceNew = schema.ForceNew
// This is just a primitive element, so go through each and
// just diff each.
subK := fmt.Sprintf("%s.%s", k, codeStr)
err := m.diff(subK, &t2, diff, d, true)
if err != nil {
return err
}
default:
return fmt.Errorf("%s: unknown element type (internal)", k)
} }
} }