From 23d36c08ab90f4957ae8e7d781907c368f5454dd Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Wed, 1 May 2013 18:47:27 +0200 Subject: [PATCH] Add GetDefault to TomlTree --- toml.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/toml.go b/toml.go index 6cfcc71..410bab6 100644 --- a/toml.go +++ b/toml.go @@ -42,6 +42,15 @@ func (t *TomlTree) Get(key string) interface{} { return (*subtree)[keys[len(keys)-1]] } +// Same as Get but with a default value +func (t *TomlTree) GetDefault(key string, def interface{}) interface{} { + val := t.Get(key) + if val == nil { + return def + } + return val; +} + // Set an element in the tree. // Key is a dot-separated path (e.g. a.b.c). // Creates all necessary intermediates trees, if needed.