From 18c26cb2eb497289354dff5a6346bec635c00918 Mon Sep 17 00:00:00 2001 From: Dave Cunningham Date: Wed, 28 Jan 2015 12:53:34 -0500 Subject: [PATCH] Add some missing Float cases --- helper/schema/field_reader.go | 2 ++ helper/schema/field_reader_diff.go | 4 ++-- helper/schema/field_reader_map.go | 4 ++-- helper/schema/field_writer_map.go | 7 +++++++ helper/schema/schema.go | 9 +++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/helper/schema/field_reader.go b/helper/schema/field_reader.go index 6636d3058..2046581b7 100644 --- a/helper/schema/field_reader.go +++ b/helper/schema/field_reader.go @@ -82,6 +82,8 @@ func addrToSchema(addr []string, schemaMap map[string]*Schema) []*Schema { fallthrough case TypeInt: fallthrough + case TypeFloat: + fallthrough case TypeString: if len(addr) > 0 { return nil diff --git a/helper/schema/field_reader_diff.go b/helper/schema/field_reader_diff.go index f13e3ece3..aaacd5d68 100644 --- a/helper/schema/field_reader_diff.go +++ b/helper/schema/field_reader_diff.go @@ -41,10 +41,10 @@ func (r *DiffFieldReader) ReadField(address []string) (FieldReadResult, error) { switch schema.Type { case TypeBool: fallthrough - case TypeFloat: - fallthrough case TypeInt: fallthrough + case TypeFloat: + fallthrough case TypeString: return r.readPrimitive(address, schema) case TypeList: diff --git a/helper/schema/field_reader_map.go b/helper/schema/field_reader_map.go index 569cf9d91..b2ed73605 100644 --- a/helper/schema/field_reader_map.go +++ b/helper/schema/field_reader_map.go @@ -23,10 +23,10 @@ func (r *MapFieldReader) ReadField(address []string) (FieldReadResult, error) { switch schema.Type { case TypeBool: fallthrough - case TypeFloat: - fallthrough case TypeInt: fallthrough + case TypeFloat: + fallthrough case TypeString: return r.readPrimitive(address, schema) case TypeList: diff --git a/helper/schema/field_writer_map.go b/helper/schema/field_writer_map.go index 1da3d2578..3c9b0bf1a 100644 --- a/helper/schema/field_writer_map.go +++ b/helper/schema/field_writer_map.go @@ -78,6 +78,8 @@ func (w *MapFieldWriter) set(addr []string, value interface{}) error { fallthrough case TypeInt: fallthrough + case TypeFloat: + fallthrough case TypeString: return w.setPrimitive(addr, value, schema) case TypeList: @@ -235,6 +237,11 @@ func (w *MapFieldWriter) setPrimitive( if err := mapstructure.Decode(v, &n); err != nil { return fmt.Errorf("%s: %s", k, err) } + case TypeFloat: + var n float64 + if err := mapstructure.Decode(v, &n); err != nil { + return fmt.Errorf("%s: %s", k, err) + } set = strconv.FormatInt(int64(n), 10) default: diff --git a/helper/schema/schema.go b/helper/schema/schema.go index e9441b4e0..f16df2d72 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -78,6 +78,7 @@ type Schema struct { // // TypeBool - bool // TypeInt - int + // TypeFloat - float64 // TypeString - string // TypeList - []interface{} // TypeMap - map[string]interface{} @@ -406,6 +407,8 @@ func (m schemaMap) Input( fallthrough case TypeInt: fallthrough + case TypeFloat: + fallthrough case TypeString: value, err = m.inputString(input, k, v) default: @@ -1084,6 +1087,12 @@ func (m schemaMap) validatePrimitive( if err := mapstructure.WeakDecode(raw, &n); err != nil { return nil, []error{err} } + case TypeFloat: + // Verify that we can parse this as an int + var n float64 + if err := mapstructure.WeakDecode(raw, &n); err != nil { + return nil, []error{err} + } case TypeString: // Verify that we can parse this as a string var n string