From 33aa9d3ee80e79e5c22b2a26bddef1d5a0121a32 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Tue, 3 Feb 2015 19:33:01 +0900 Subject: [PATCH 1/2] Fix stringer error on helper/schema/schema.go --- helper/schema/schema.go | 43 ----------------------------- helper/schema/valuetype.go | 46 +++++++++++++++++++++++++++++++ helper/schema/valuetype_string.go | 13 ++++++--- 3 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 helper/schema/valuetype.go diff --git a/helper/schema/schema.go b/helper/schema/schema.go index f16df2d72..fc52548a4 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -11,8 +11,6 @@ // A good starting point is to view the Provider structure. package schema -//go:generate stringer -type=ValueType - import ( "fmt" "os" @@ -25,47 +23,6 @@ import ( "github.com/mitchellh/mapstructure" ) -// ValueType is an enum of the type that can be represented by a schema. -type ValueType int - -const ( - TypeInvalid ValueType = iota - TypeBool - TypeInt - TypeFloat - TypeString - TypeList - TypeMap - TypeSet - typeObject -) - -// Zero returns the zero value for a type. -func (t ValueType) Zero() interface{} { - switch t { - case TypeInvalid: - return nil - case TypeBool: - return false - case TypeInt: - return 0 - case TypeFloat: - return 0.0 - case TypeString: - return "" - case TypeList: - return []interface{}{} - case TypeMap: - return map[string]interface{}{} - case TypeSet: - return nil - case typeObject: - return map[string]interface{}{} - default: - panic(fmt.Sprintf("unknown type %s", t)) - } -} - // Schema is used to describe the structure of a value. // // Read the documentation of the struct elements for important details. diff --git a/helper/schema/valuetype.go b/helper/schema/valuetype.go new file mode 100644 index 000000000..b7b7ac810 --- /dev/null +++ b/helper/schema/valuetype.go @@ -0,0 +1,46 @@ +package schema + +//go:generate stringer -type=ValueType valuetype.go + +import "fmt" + +// ValueType is an enum of the type that can be represented by a schema. +type ValueType int + +const ( + TypeInvalid ValueType = iota + TypeBool + TypeInt + TypeFloat + TypeString + TypeList + TypeMap + TypeSet + typeObject +) + +// Zero returns the zero value for a type. +func (t ValueType) Zero() interface{} { + switch t { + case TypeInvalid: + return nil + case TypeBool: + return false + case TypeInt: + return 0 + case TypeFloat: + return 0.0 + case TypeString: + return "" + case TypeList: + return []interface{}{} + case TypeMap: + return map[string]interface{}{} + case TypeSet: + return nil + case typeObject: + return map[string]interface{}{} + default: + panic(fmt.Sprintf("unknown type %s", t)) + } +} diff --git a/helper/schema/valuetype_string.go b/helper/schema/valuetype_string.go index c011d3ec2..484a83963 100644 --- a/helper/schema/valuetype_string.go +++ b/helper/schema/valuetype_string.go @@ -1,4 +1,4 @@ -// generated by stringer -type=ValueType; DO NOT EDIT +// generated by stringer -type=ValueType valuetype.go; DO NOT EDIT package schema @@ -6,11 +6,16 @@ import "fmt" const _ValueType_name = "TypeInvalidTypeBoolTypeIntTypeFloatTypeStringTypeListTypeMapTypeSettypeObject" -var _ValueType_index = [...]uint8{0, 11, 19, 26, 35, 45, 53, 60, 67, 77} +var _ValueType_index = [...]uint8{11, 19, 26, 35, 45, 53, 60, 67, 77} func (i ValueType) String() string { - if i < 0 || i+1 >= ValueType(len(_ValueType_index)) { + if i < 0 || i >= ValueType(len(_ValueType_index)) { return fmt.Sprintf("ValueType(%d)", i) } - return _ValueType_name[_ValueType_index[i]:_ValueType_index[i+1]] + hi := _ValueType_index[i] + lo := uint8(0) + if i > 0 { + lo = _ValueType_index[i-1] + } + return _ValueType_name[lo:hi] } From f6367a779abac2c8b66ed10ddfe56afe1d156415 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Wed, 4 Feb 2015 01:54:14 +0900 Subject: [PATCH 2/2] regenerate with new stringer. --- helper/schema/valuetype_string.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/helper/schema/valuetype_string.go b/helper/schema/valuetype_string.go index 484a83963..fec00944e 100644 --- a/helper/schema/valuetype_string.go +++ b/helper/schema/valuetype_string.go @@ -6,16 +6,11 @@ import "fmt" const _ValueType_name = "TypeInvalidTypeBoolTypeIntTypeFloatTypeStringTypeListTypeMapTypeSettypeObject" -var _ValueType_index = [...]uint8{11, 19, 26, 35, 45, 53, 60, 67, 77} +var _ValueType_index = [...]uint8{0, 11, 19, 26, 35, 45, 53, 60, 67, 77} func (i ValueType) String() string { - if i < 0 || i >= ValueType(len(_ValueType_index)) { + if i < 0 || i+1 >= ValueType(len(_ValueType_index)) { return fmt.Sprintf("ValueType(%d)", i) } - hi := _ValueType_index[i] - lo := uint8(0) - if i > 0 { - lo = _ValueType_index[i-1] - } - return _ValueType_name[lo:hi] + return _ValueType_name[_ValueType_index[i]:_ValueType_index[i+1]] }