diff --git a/decoder.go b/decoder.go index 7fb14ab..2fcac72 100644 --- a/decoder.go +++ b/decoder.go @@ -111,6 +111,13 @@ func (d *decoder) decodeInt(name string, o *hcl.Object, result reflect.Value) er switch o.Type { case hcl.ValueTypeInt: result.Set(reflect.ValueOf(o.Value.(int))) + case hcl.ValueTypeString: + v, err := strconv.ParseInt(o.Value.(string), 0, 0) + if err != nil { + return err + } + + result.SetInt(int64(v)) default: return fmt.Errorf("%s: unknown type %s", name, o.Type) } diff --git a/decoder_test.go b/decoder_test.go index 36e85f6..3a488c0 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -424,3 +424,18 @@ func TestDecode_structureMap(t *testing.T) { } } } + +func TestDecode_intString(t *testing.T) { + var value struct { + Count int + } + + err := Decode(&value, testReadFile(t, "basic_int_string.hcl")) + if err != nil { + t.Fatalf("err: %s", err) + } + + if value.Count != 3 { + t.Fatalf("bad: %#v", value.Count) + } +} diff --git a/test-fixtures/basic_int_string.hcl b/test-fixtures/basic_int_string.hcl new file mode 100644 index 0000000..4e415da --- /dev/null +++ b/test-fixtures/basic_int_string.hcl @@ -0,0 +1 @@ +count = "3"