diff --git a/stringmap.go b/stringmap.go new file mode 100644 index 0000000..809d5a4 --- /dev/null +++ b/stringmap.go @@ -0,0 +1,8 @@ +package cubeutil + +func GetStringMapValue(source map[string]string, key string, fallBack string) string { + if value, ok := source[key]; ok { + return value + } + return fallBack +} diff --git a/stringmap_test.go b/stringmap_test.go new file mode 100644 index 0000000..40cd481 --- /dev/null +++ b/stringmap_test.go @@ -0,0 +1,17 @@ +package cubeutil_test + +import ( + "testing" + "github.com/cubex/cubeutil-go" +) + +func TestGetMapValue(t *testing.T) { + useMap := make(map[string]string) + useMap["found"] = "Found" + if cubeutil.GetStringMapValue(useMap, "found", "Not Found") != "Found" { + t.Fail() + } + if cubeutil.GetStringMapValue(useMap, "not_found", "Not Found") != "Not Found" { + t.Fail() + } +}