-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
helper/schema: change GetOk semantics to mean non-zero #993
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,7 @@ func TestValueType_Zero(t *testing.T) { | |
{TypeString, ""}, | ||
{TypeList, []interface{}{}}, | ||
{TypeMap, map[string]interface{}{}}, | ||
{TypeSet, nil}, | ||
{TypeSet, new(Set)}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be the correct behavior. The zero value of a set is an empty set, not a nil value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed |
||
} | ||
|
||
for i, tc := range cases { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ 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 | ||
|
||
|
@@ -19,28 +17,5 @@ const ( | |
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)) | ||
} | ||
} | ||
// NOTE: ValueType has more functions defined on it in schema.go. We can't | ||
// put them here because we reference other files. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. <3 for the note |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the behavior change mentioned in the description.