From 6c5e1969ac0e3bd59d17391410cd5c4c785adbb7 Mon Sep 17 00:00:00 2001 From: vishalnayak Date: Fri, 10 Jun 2016 10:42:01 -0400 Subject: [PATCH] Added GetDefaultOrZero method to FieldData --- logical/framework/field_data.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/logical/framework/field_data.go b/logical/framework/field_data.go index f76c01bc7..4edeac1e9 100644 --- a/logical/framework/field_data.go +++ b/logical/framework/field_data.go @@ -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) {