summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkballou <kballou@devnulllabs.io>2015-04-21 12:42:28 -0600
committerkballou <kballou@devnulllabs.io>2015-04-21 12:43:15 -0600
commit277733731a407a7790a02494ec372fff721fc348 (patch)
tree470a589665fa96db3f27d684c33ee47cc500a7d8
parentd6fb1264cde71146d2363eb43ea01f263345935c (diff)
downloadgohadoopxml-277733731a407a7790a02494ec372fff721fc348.tar.gz
gohadoopxml-277733731a407a7790a02494ec372fff721fc348.tar.xz
Add `GetPropertyValue` function
Linearly search through properties for given key, if found, return value, else return error object.
-rw-r--r--gohadoopxml.go10
-rw-r--r--gohadoopxml_test.go19
2 files changed, 29 insertions, 0 deletions
diff --git a/gohadoopxml.go b/gohadoopxml.go
index d6d5721..336a673 100644
--- a/gohadoopxml.go
+++ b/gohadoopxml.go
@@ -2,6 +2,7 @@ package gohadoopxml
import (
"encoding/xml"
+ "errors"
"io/ioutil"
"log"
"os"
@@ -36,6 +37,15 @@ func ParseXML(filename string) (Configuration, error) {
return config, nil
}
+func GetPropertyValue(key string, config Configuration) (string, error) {
+ for _, p := range config.Properties {
+ if key == p.Name {
+ return p.Value, nil
+ }
+ }
+ return "", errors.New("Key not found")
+}
+
func MergeConfigurations(configs ...Configuration) Configuration {
var new_config Configuration
for _, config := range configs {
diff --git a/gohadoopxml_test.go b/gohadoopxml_test.go
index aa81010..ab6c36e 100644
--- a/gohadoopxml_test.go
+++ b/gohadoopxml_test.go
@@ -38,3 +38,22 @@ func TestMergeConfiguration(t *testing.T) {
t.Fail()
}
}
+
+func TestGetPropertyValue(t *testing.T) {
+ var config = Configuration{
+ Properties: []Property{
+ {
+ Name: "foo",
+ Value: "bar",
+ },
+ },
+ }
+ result, err := GetPropertyValue("foo", config)
+ if err != nil || result != "bar" {
+ t.Fail()
+ }
+ result, err = GetPropertyValue("fizz", config)
+ if err == nil {
+ t.Fail()
+ }
+}