Added logger util GetOrCreateMap() and started using it everywhere.
[arvados.git] / sdk / go / logger / util.go
diff --git a/sdk/go/logger/util.go b/sdk/go/logger/util.go
new file mode 100644 (file)
index 0000000..6425aca
--- /dev/null
@@ -0,0 +1,20 @@
+// Helper methods for interacting with Logger.
+package logger
+
+// Retrieves the map[string]interface{} stored at parent[key] if it
+// exists, otherwise it makes it and stores it there.
+// This is useful for logger because you may not know if a map you
+// need has already been created.
+func GetOrCreateMap(
+       parent map[string]interface{},
+       key string) (child map[string]interface{}) {
+       read, exists := parent[key]
+       if exists {
+               child = read.(map[string]interface{})
+
+       } else {
+               child = make(map[string]interface{})
+               parent[key] = child
+       }
+       return
+}