Skip to content

Commit

Permalink
Merge pull request #1513 from hashicorp/field-data-get-default
Browse files Browse the repository at this point in the history
Added GetDefaultOrZero method to FieldData
  • Loading branch information
vishalnayak committed Jun 10, 2016
2 parents a1adb40 + 583c968 commit 1e67cd8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions logical/framework/field_data.go
Expand Up @@ -63,6 +63,18 @@ func (d *FieldData) Get(k string) interface{} {
return value
}

// GetDefaultOrZero gets the default value set on the schema for the given
// field. If there is no default value set, the zero value of the type
// will be returned.
func (d *FieldData) GetDefaultOrZero(k string) interface{} {
schema, ok := d.Schema[k]
if !ok {
panic(fmt.Sprintf("field %s not in the schema", k))
}

return schema.DefaultOrZero()
}

// GetOk gets the value for the given field. The second return value
// will be false if the key is invalid or the key is not set at all.
func (d *FieldData) GetOk(k string) (interface{}, bool) {
Expand Down

0 comments on commit 1e67cd8

Please sign in to comment.