Skip to content

Commit

Permalink
String Map helper
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed May 31, 2017
1 parent 181f6e6 commit 1c6c49c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions stringmap.go
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions stringmap_test.go
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit 1c6c49c

Please sign in to comment.