Updating godep to minio-io/godep

This commit is contained in:
Frederick F. Kautz IV 2015-04-01 20:57:27 -07:00
parent 8757ccf9a3
commit a689769245
34 changed files with 211 additions and 225 deletions

2
Godeps/Godeps.json generated
View File

@ -1,6 +1,6 @@
{ {
"ImportPath": "github.com/minio-io/minio", "ImportPath": "github.com/minio-io/minio",
"GoVersion": "go1.4", "GoVersion": "go1.4.2",
"Packages": [ "Packages": [
"./..." "./..."
], ],

View File

@ -9,21 +9,21 @@ const (
DefaultElementTag = "element" DefaultElementTag = "element"
) )
// Encode arbitrary value as XML. // Encode arbitrary value as XML.
// //
// Note: unmarshaling the resultant // Note: unmarshaling the resultant
// XML may not return the original value, since tag labels may have been injected // XML may not return the original value, since tag labels may have been injected
// to create the XML representation of the value. // to create the XML representation of the value.
/* /*
Encode an arbitrary JSON object. Encode an arbitrary JSON object.
package main package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github/clbanning/mxj" "github/clbanning/mxj"
) )
func main() { func main() {
jsondata := []byte(`[ jsondata := []byte(`[
{ "somekey":"somevalue" }, { "somekey":"somevalue" },
@ -42,7 +42,7 @@ const (
} }
fmt.Println(string(x)) fmt.Println(string(x))
} }
output: output:
<mydoc> <mydoc>
<somekey>somevalue</somekey> <somekey>somevalue</somekey>
@ -110,7 +110,6 @@ func AnyXml(v interface{}, tags ...string) ([]byte, error) {
return b, err return b, err
} }
// Encode an arbitrary value as a pretty XML string. // Encode an arbitrary value as a pretty XML string.
// Alternative values for DefaultRootTag and DefaultElementTag can be set as: // Alternative values for DefaultRootTag and DefaultElementTag can be set as:
// AnyXmlIndent( v, "", " ", myRootTag, myElementTag). // AnyXmlIndent( v, "", " ", myRootTag, myElementTag).

View File

@ -43,7 +43,7 @@ func TestAnyXml(t *testing.T) {
} }
fmt.Println("[]->x:", string(x)) fmt.Println("[]->x:", string(x))
a := []interface{}{ "try", "this", 3.14159265, true } a := []interface{}{"try", "this", 3.14159265, true}
x, err = AnyXml(a) x, err = AnyXml(a)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -82,7 +82,7 @@ func TestAnyXmlIndent(t *testing.T) {
} }
fmt.Println("[]->x:\n", string(x)) fmt.Println("[]->x:\n", string(x))
a := []interface{}{ "try", "this", 3.14159265, true } a := []interface{}{"try", "this", 3.14159265, true}
x, err = AnyXmlIndent(a, "", " ") x, err = AnyXmlIndent(a, "", " ")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -36,4 +36,3 @@ var jsondata = []byte(`
{"book":{"author":"John Hawkes","review":"A lyrical novel about the construction of Ft. Peck Dam in Montana.","title":"The Beetle Leg"}} {"book":{"author":"John Hawkes","review":"A lyrical novel about the construction of Ft. Peck Dam in Montana.","title":"The Beetle Leg"}}
{"book":{"author":{"first_name":"T.E.","last_name":"Porter"},"review":"A magical novella.","title":"King's Day"}} {"book":{"author":{"first_name":"T.E.","last_name":"Porter"},"review":"A magical novella.","title":"King's Day"}}
{ "here":"we", "put":"in", "an":error }`) { "here":"we", "put":"in", "an":error }`)

View File

@ -31,7 +31,7 @@ SUMMARY
Marshal Map value, 'm', to an XML Writer (io.Writer): Marshal Map value, 'm', to an XML Writer (io.Writer):
err := m.XmlWriter(xmlWriter) err := m.XmlWriter(xmlWriter)
raw, err := m.XmlWriterRaw(xmlWriter) // 'raw' is the raw XML that was written on xmlWriter raw, err := m.XmlWriterRaw(xmlWriter) // 'raw' is the raw XML that was written on xmlWriter
Also, for prettified output: Also, for prettified output:
xmlValue, err := m.XmlIndent(prefix, indent, ...) xmlValue, err := m.XmlIndent(prefix, indent, ...)
err := m.XmlIndentWriter(xmlWriter, prefix, indent, ...) err := m.XmlIndentWriter(xmlWriter, prefix, indent, ...)
@ -72,7 +72,7 @@ XML PARSING CONVENTIONS
- Attributes are parsed to map[string]interface{} values by prefixing a hyphen, '-', - Attributes are parsed to map[string]interface{} values by prefixing a hyphen, '-',
to the attribute label. (PrependAttrWithHyphen(false) will override this.) to the attribute label. (PrependAttrWithHyphen(false) will override this.)
- If the element is a simple element and has attributes, the element value - If the element is a simple element and has attributes, the element value
is given the key '#text' for its map[string]interface{} representation. is given the key '#text' for its map[string]interface{} representation.
XML ENCODING CONVENTIONS XML ENCODING CONVENTIONS

View File

@ -8,8 +8,8 @@ package mxj_test
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"github.com/clbanning/mxj" "github.com/clbanning/mxj"
"io"
) )
func ExampleHandleXmlReader() { func ExampleHandleXmlReader() {
@ -246,59 +246,59 @@ func ExampleMap_ValuesForKeyPath() {
} }
func ExampleMap_UpdateValuesForPath() { func ExampleMap_UpdateValuesForPath() {
/* /*
var biblioDoc = []byte(`
<biblio>
<author>
<name>William Gaddis</name>
<books>
<book>
<title>The Recognitions</title>
<date>1955</date>
<review>A novel that changed the face of American literature.</review>
</book>
<book>
<title>JR</title>
<date>1975</date>
<review>Winner of National Book Award for Fiction.</review>
</book>
</books>
</author>
</biblio>`)
... var biblioDoc = []byte(`
m, merr := mxj.NewMapXml(biblioDoc) <biblio>
if merr != nil { <author>
// handle error <name>William Gaddis</name>
} <books>
<book>
<title>The Recognitions</title>
<date>1955</date>
<review>A novel that changed the face of American literature.</review>
</book>
<book>
<title>JR</title>
<date>1975</date>
<review>Winner of National Book Award for Fiction.</review>
</book>
</books>
</author>
</biblio>`)
// change 'review' for a book ...
count, err := m.UpdateValuesForPath("review:National Book Award winner." "*.*.*.*", "title:JR") m, merr := mxj.NewMapXml(biblioDoc)
if err != nil { if merr != nil {
// handle error // handle error
} }
...
// change 'date' value from string type to float64 type // change 'review' for a book
// Note: the following is equivalent to m, merr := NewMapXml(biblioDoc, mxj.Cast). count, err := m.UpdateValuesForPath("review:National Book Award winner." "*.*.*.*", "title:JR")
path := m.PathForKeyShortest("date") if err != nil {
v, err := m.ValuesForPath(path) // handle error
if err != nil { }
// handle error ...
}
var total int // change 'date' value from string type to float64 type
for _, vv := range v { // Note: the following is equivalent to m, merr := NewMapXml(biblioDoc, mxj.Cast).
oldVal := "date:" + vv.(string) path := m.PathForKeyShortest("date")
newVal := "date:" + vv.(string) + ":num" v, err := m.ValuesForPath(path)
n, err := m.UpdateValuesForPath(newVal, path, oldVal) if err != nil {
if err != nil { // handle error
// handle error }
} var total int
total += n for _, vv := range v {
} oldVal := "date:" + vv.(string)
... newVal := "date:" + vv.(string) + ":num"
*/ n, err := m.UpdateValuesForPath(newVal, path, oldVal)
if err != nil {
// handle error
}
total += n
}
...
*/
} }
func ExampleMap_Copy() { func ExampleMap_Copy() {
@ -313,34 +313,32 @@ func ExampleMap_Copy() {
private string private string
} }
s := str{IntVal: 4, StrVal: "now's the time", FloatVal: 3.14159, BoolVal: true, private: "Skies are blue"} s := str{IntVal: 4, StrVal: "now's the time", FloatVal: 3.14159, BoolVal: true, private: "Skies are blue"}
m := make(map[string]interface{},0) m := make(map[string]interface{}, 0)
m["struct"] = interface{}(s) m["struct"] = interface{}(s)
m["struct_ptr"] = interface{}(&s) m["struct_ptr"] = interface{}(&s)
m["misc"] = interface{}(`Now is the time`) m["misc"] = interface{}(`Now is the time`)
mv := mxj.Map(m) mv := mxj.Map(m)
cp,_ := mv.Copy() cp, _ := mv.Copy()
fmt.Printf("mv:%s\n", mv.StringIndent(2)) fmt.Printf("mv:%s\n", mv.StringIndent(2))
fmt.Printf("cp:%s\n", cp.StringIndent(2)) fmt.Printf("cp:%s\n", cp.StringIndent(2))
// Output: // Output:
// mv: // mv:
// struct :[unknown] mxj_test.str{IntVal:4, StrVal:"now's the time", FloatVal:3.14159, BoolVal:true, private:"Skies are blue"} // struct :[unknown] mxj_test.str{IntVal:4, StrVal:"now's the time", FloatVal:3.14159, BoolVal:true, private:"Skies are blue"}
// struct_ptr :[unknown] &mxj_test.str{IntVal:4, StrVal:"now's the time", FloatVal:3.14159, BoolVal:true, private:"Skies are blue"} // struct_ptr :[unknown] &mxj_test.str{IntVal:4, StrVal:"now's the time", FloatVal:3.14159, BoolVal:true, private:"Skies are blue"}
// misc :[string] Now is the time // misc :[string] Now is the time
// cp: // cp:
// misc :[string] Now is the time // misc :[string] Now is the time
// struct : // struct :
// int :[float64] 4.00e+00 // int :[float64] 4.00e+00
// str :[string] now's the time // str :[string] now's the time
// float :[float64] 3.14e+00 // float :[float64] 3.14e+00
// bool :[bool] true // bool :[bool] true
// struct_ptr : // struct_ptr :
// int :[float64] 4.00e+00 // int :[float64] 4.00e+00
// str :[string] now's the time // str :[string] now's the time
// float :[float64] 3.14e+00 // float :[float64] 3.14e+00
// bool :[bool] true // bool :[bool] true
} }

View File

@ -4,8 +4,8 @@ package main
import ( import (
"fmt" "fmt"
"log"
"github.com/clbanning/mxj" "github.com/clbanning/mxj"
"log"
) )
var xmldata = []byte(` var xmldata = []byte(`

View File

@ -1,5 +1,5 @@
// getmetrics1.go - transform Eclipse Metrics (v3) XML report into CSV files for each metric // getmetrics1.go - transform Eclipse Metrics (v3) XML report into CSV files for each metric
// Uses NewMapXmlReader on os.File without copying the raw XML into a buffer while decoding.. // Uses NewMapXmlReader on os.File without copying the raw XML into a buffer while decoding..
// Shows no significant overhead for not first buffering large XML file as in getmetrics2.go. // Shows no significant overhead for not first buffering large XML file as in getmetrics2.go.
/* /*
@ -38,10 +38,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/clbanning/mxj"
"log" "log"
"os" "os"
"time" "time"
"github.com/clbanning/mxj"
) )
func main() { func main() {

View File

@ -39,10 +39,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/clbanning/mxj"
"log" "log"
"os" "os"
"time" "time"
"github.com/clbanning/mxj"
) )
func main() { func main() {
@ -81,7 +81,7 @@ func main() {
fmt.Println(time.Now().String(), "... XML Unmarshaled - len:", len(m)) fmt.Println(time.Now().String(), "... XML Unmarshaled - len:", len(m))
// Get just the key values of interest. // Get just the key values of interest.
// Could also use m.ValuesForKey("Metric"), // Could also use m.ValuesForKey("Metric"),
// since there's just the one path. // since there's just the one path.
metricVals, err := m.ValuesForPath("Metrics.Metric") metricVals, err := m.ValuesForPath("Metrics.Metric")
if err != nil { if err != nil {

View File

@ -40,10 +40,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/clbanning/mxj"
"log" "log"
"os" "os"
"time" "time"
"github.com/clbanning/mxj"
) )
func main() { func main() {

View File

@ -1,7 +1,7 @@
// getmetrics2.go - transform Eclipse Metrics (v3) XML report into CSV files for each metric // getmetrics2.go - transform Eclipse Metrics (v3) XML report into CSV files for each metric
// Uses an in-memory buffer for the XML data and direct XML decoding of the buffer into a Map. // Uses an in-memory buffer for the XML data and direct XML decoding of the buffer into a Map.
// Then XML buffer is decoded into a Map while the raw XML is copied using NewMapXmlReaderRaw() // Then XML buffer is decoded into a Map while the raw XML is copied using NewMapXmlReaderRaw()
// to illustrate processing overhead relative to getmetrics2.go. Not a practical example, // to illustrate processing overhead relative to getmetrics2.go. Not a practical example,
// but confirms the getmetrics1.go vs. getmetrics3.go use case. // but confirms the getmetrics1.go vs. getmetrics3.go use case.
/* /*
@ -41,10 +41,10 @@ import (
"bytes" "bytes"
"flag" "flag"
"fmt" "fmt"
"github.com/clbanning/mxj"
"log" "log"
"os" "os"
"time" "time"
"github.com/clbanning/mxj"
) )
func main() { func main() {
@ -79,7 +79,7 @@ func main() {
// load XML into a Map value // load XML into a Map value
// Note: there is a single record with root tag of "Metrics". // Note: there is a single record with root tag of "Metrics".
m, raw, merr := mxj.NewMapXmlReaderRaw(xmlReader) // don't catch the pointer to raw XML m, raw, merr := mxj.NewMapXmlReaderRaw(xmlReader) // don't catch the pointer to raw XML
if merr != nil { if merr != nil {
log.Fatal("merr:", merr.Error()) log.Fatal("merr:", merr.Error())
} }
@ -87,7 +87,7 @@ func main() {
fmt.Println("raw XML buffer size (should be same as File size):", len(*raw)) fmt.Println("raw XML buffer size (should be same as File size):", len(*raw))
// Get just the key values of interest. // Get just the key values of interest.
// Could also use m.ValuesForKey("Metric"), // Could also use m.ValuesForKey("Metric"),
// since there's just the one path. // since there's just the one path.
metricVals, err := m.ValuesForPath("Metrics.Metric") metricVals, err := m.ValuesForPath("Metrics.Metric")
if err != nil { if err != nil {

View File

@ -6,8 +6,8 @@ package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"github.com/clbanning/mxj" "github.com/clbanning/mxj"
"io"
) )
// Demo how to compensate for irregular tag labels in data. // Demo how to compensate for irregular tag labels in data.

View File

@ -108,9 +108,9 @@ func fullPath(xmldata [][]byte) {
} }
func partPath1(msg []byte) { func partPath1(msg []byte) {
fmt.Println("\nmsg:",string(msg)) fmt.Println("\nmsg:", string(msg))
m, _ := mxj.NewMapXml(msg) m, _ := mxj.NewMapXml(msg)
fmt.Println("m:",m.StringIndent()) fmt.Println("m:", m.StringIndent())
path := "Envelope.Body.*.*.ClaimStatusCodeRecord" path := "Envelope.Body.*.*.ClaimStatusCodeRecord"
values, err := m.ValueForPath(path) values, err := m.ValueForPath(path)
if err != nil { if err != nil {
@ -130,9 +130,9 @@ func partPath1(msg []byte) {
} }
func partPath2(msg []byte) { func partPath2(msg []byte) {
fmt.Println("\nmsg:",string(msg)) fmt.Println("\nmsg:", string(msg))
m, _ := mxj.NewMapXml(msg) m, _ := mxj.NewMapXml(msg)
fmt.Println("m:",m.StringIndent()) fmt.Println("m:", m.StringIndent())
path := "Envelope.Body.*.*.*" path := "Envelope.Body.*.*.*"
values, err := m.ValueForPath(path) values, err := m.ValueForPath(path)
if err != nil { if err != nil {
@ -152,9 +152,9 @@ func partPath2(msg []byte) {
} }
func partPath3(msg []byte) { func partPath3(msg []byte) {
fmt.Println("\nmsg:",string(msg)) fmt.Println("\nmsg:", string(msg))
m, _ := mxj.NewMapXml(msg) m, _ := mxj.NewMapXml(msg)
fmt.Println("m:",m.StringIndent()) fmt.Println("m:", m.StringIndent())
path := "*.*.*.*.*" path := "*.*.*.*.*"
values, err := m.ValueForPath(path) values, err := m.ValueForPath(path)
if err != nil { if err != nil {
@ -174,9 +174,9 @@ func partPath3(msg []byte) {
} }
func partPath4(msg []byte) { func partPath4(msg []byte) {
fmt.Println("\nmsg:",string(msg)) fmt.Println("\nmsg:", string(msg))
m, _ := mxj.NewMapXml(msg) m, _ := mxj.NewMapXml(msg)
fmt.Println("m:",m.StringIndent()) fmt.Println("m:", m.StringIndent())
path := "*.*.*.*.*.Description" path := "*.*.*.*.*.Description"
values, err := m.ValueForPath(path) values, err := m.ValueForPath(path)
if err != nil { if err != nil {
@ -196,9 +196,9 @@ func partPath4(msg []byte) {
} }
func partPath5(msg []byte) { func partPath5(msg []byte) {
fmt.Println("\nmsg:",string(msg)) fmt.Println("\nmsg:", string(msg))
m, _ := mxj.NewMapXml(msg) m, _ := mxj.NewMapXml(msg)
fmt.Println("m:",m.StringIndent()) fmt.Println("m:", m.StringIndent())
path := "*.*.*.*.*.*" path := "*.*.*.*.*.*"
values, err := m.ValueForPath(path) values, err := m.ValueForPath(path)
if err != nil { if err != nil {
@ -218,9 +218,9 @@ func partPath5(msg []byte) {
} }
func partPath6(msg []byte) { func partPath6(msg []byte) {
fmt.Println("\nmsg:",string(msg)) fmt.Println("\nmsg:", string(msg))
m, _ := mxj.NewMapXml(msg) m, _ := mxj.NewMapXml(msg)
fmt.Println("m:",m.StringIndent()) fmt.Println("m:", m.StringIndent())
path := "*.*.*.*.*.*.*" path := "*.*.*.*.*.*.*"
values, err := m.ValueForPath(path) values, err := m.ValueForPath(path)
if err != nil { if err != nil {

View File

@ -45,6 +45,6 @@ func main() {
} }
for _, v := range values { for _, v := range values {
fmt.Println("v:",v) fmt.Println("v:", v)
} }
} }

View File

@ -41,4 +41,3 @@ func main() {
} }
var s = []byte(`{ "DBInstances": [ { "PubliclyAccessible": true, "MasterUsername": "postgres", "LicenseModel": "postgresql-license", "VpcSecurityGroups": [ { "Status": "active", "VpcSecurityGroupId": "sg-e72a4282" } ], "InstanceCreateTime": "2014-06-29T03:52:59.268Z", "OptionGroupMemberships": [ { "Status": "in-sync", "OptionGroupName": "default:postgres-9-3" } ], "PendingModifiedValues": {}, "Engine": "postgres", "MultiAZ": true, "LatestRestorableTime": "2014-06-29T12:00:34Z", "DBSecurityGroups": [ { "Status": "active", "DBSecurityGroupName": "production-dbsecuritygroup-q4f0ugxpjck8" } ], "DBParameterGroups": [ { "DBParameterGroupName": "default.postgres9.3", "ParameterApplyStatus": "in-sync" } ], "AutoMinorVersionUpgrade": true, "PreferredBackupWindow": "06:59-07:29", "DBSubnetGroup": { "Subnets": [ { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-34e5d01c", "SubnetAvailabilityZone": { "Name": "us-east-1b", "ProvisionedIopsCapable": false } }, { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-50759d27", "SubnetAvailabilityZone": { "Name": "us-east-1c", "ProvisionedIopsCapable": false } }, { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-450a1f03", "SubnetAvailabilityZone": { "Name": "us-east-1d", "ProvisionedIopsCapable": false } } ], "DBSubnetGroupName": "default", "VpcId": "vpc-acb86cc9", "DBSubnetGroupDescription": "default", "SubnetGroupStatus": "Complete" }, "SecondaryAvailabilityZone": "us-east-1b", "ReadReplicaDBInstanceIdentifiers": [], "AllocatedStorage": 15, "BackupRetentionPeriod": 1, "DBName": "deis", "PreferredMaintenanceWindow": "fri:05:52-fri:06:22", "Endpoint": { "Port": 5432, "Address": "production.cfk8mskkbkeu.us-east-1.rds.amazonaws.com" }, "DBInstanceStatus": "available", "EngineVersion": "9.3.3", "AvailabilityZone": "us-east-1c", "DBInstanceClass": "db.m1.small", "DBInstanceIdentifier": "production" } ] }`) var s = []byte(`{ "DBInstances": [ { "PubliclyAccessible": true, "MasterUsername": "postgres", "LicenseModel": "postgresql-license", "VpcSecurityGroups": [ { "Status": "active", "VpcSecurityGroupId": "sg-e72a4282" } ], "InstanceCreateTime": "2014-06-29T03:52:59.268Z", "OptionGroupMemberships": [ { "Status": "in-sync", "OptionGroupName": "default:postgres-9-3" } ], "PendingModifiedValues": {}, "Engine": "postgres", "MultiAZ": true, "LatestRestorableTime": "2014-06-29T12:00:34Z", "DBSecurityGroups": [ { "Status": "active", "DBSecurityGroupName": "production-dbsecuritygroup-q4f0ugxpjck8" } ], "DBParameterGroups": [ { "DBParameterGroupName": "default.postgres9.3", "ParameterApplyStatus": "in-sync" } ], "AutoMinorVersionUpgrade": true, "PreferredBackupWindow": "06:59-07:29", "DBSubnetGroup": { "Subnets": [ { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-34e5d01c", "SubnetAvailabilityZone": { "Name": "us-east-1b", "ProvisionedIopsCapable": false } }, { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-50759d27", "SubnetAvailabilityZone": { "Name": "us-east-1c", "ProvisionedIopsCapable": false } }, { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-450a1f03", "SubnetAvailabilityZone": { "Name": "us-east-1d", "ProvisionedIopsCapable": false } } ], "DBSubnetGroupName": "default", "VpcId": "vpc-acb86cc9", "DBSubnetGroupDescription": "default", "SubnetGroupStatus": "Complete" }, "SecondaryAvailabilityZone": "us-east-1b", "ReadReplicaDBInstanceIdentifiers": [], "AllocatedStorage": 15, "BackupRetentionPeriod": 1, "DBName": "deis", "PreferredMaintenanceWindow": "fri:05:52-fri:06:22", "Endpoint": { "Port": 5432, "Address": "production.cfk8mskkbkeu.us-east-1.rds.amazonaws.com" }, "DBInstanceStatus": "available", "EngineVersion": "9.3.3", "AvailabilityZone": "us-east-1c", "DBInstanceClass": "db.m1.small", "DBInstanceIdentifier": "production" } ] }`)

View File

@ -9,7 +9,7 @@ import (
type Maps []Map type Maps []Map
func NewMaps() Maps { func NewMaps() Maps {
return make(Maps,0) return make(Maps, 0)
} }
type MapRaw struct { type MapRaw struct {
@ -33,7 +33,7 @@ func NewMapsFromJsonFile(name string) (Maps, error) {
} }
defer fh.Close() defer fh.Close()
am := make([]Map,0) am := make([]Map, 0)
for { for {
m, raw, err := NewMapJsonReaderRaw(fh) m, raw, err := NewMapJsonReaderRaw(fh)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
@ -65,7 +65,7 @@ func NewMapsFromJsonFileRaw(name string) ([]MapRaw, error) {
} }
defer fh.Close() defer fh.Close()
am := make([]MapRaw,0) am := make([]MapRaw, 0)
for { for {
mr := new(MapRaw) mr := new(MapRaw)
mr.M, mr.R, err = NewMapJsonReaderRaw(fh) mr.M, mr.R, err = NewMapJsonReaderRaw(fh)
@ -104,7 +104,7 @@ func NewMapsFromXmlFile(name string) (Maps, error) {
} }
defer fh.Close() defer fh.Close()
am := make([]Map,0) am := make([]Map, 0)
for { for {
m, raw, err := NewMapXmlReaderRaw(fh) m, raw, err := NewMapXmlReaderRaw(fh)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
@ -130,7 +130,6 @@ func NewMapsFromXmlFileRaw(name string) ([]MapRaw, error) {
XmlWriterBufSize = x XmlWriterBufSize = x
}() }()
fi, err := os.Stat(name) fi, err := os.Stat(name)
if err != nil { if err != nil {
return nil, err return nil, err
@ -145,7 +144,7 @@ func NewMapsFromXmlFileRaw(name string) ([]MapRaw, error) {
} }
defer fh.Close() defer fh.Close()
am := make([]MapRaw,0) am := make([]MapRaw, 0)
for { for {
mr := new(MapRaw) mr := new(MapRaw)
mr.M, mr.R, err = NewMapXmlReaderRaw(fh) mr.M, mr.R, err = NewMapXmlReaderRaw(fh)
@ -298,4 +297,3 @@ func (mvs Maps) XmlFileIndent(file, prefix, indent string) error {
fh.WriteString(s) fh.WriteString(s)
return nil return nil
} }

View File

@ -104,7 +104,7 @@ func TestNewXmFileRaw(t *testing.T) {
func TestMaps(t *testing.T) { func TestMaps(t *testing.T) {
fmt.Println("TestMaps()") fmt.Println("TestMaps()")
mvs := NewMaps() mvs := NewMaps()
for i := 0 ; i < 2 ; i++ { for i := 0; i < 2; i++ {
m, _ := NewMapJson([]byte(`{ "this":"is", "a":"test" }`)) m, _ := NewMapJson([]byte(`{ "this":"is", "a":"test" }`))
mvs = append(mvs, m) mvs = append(mvs, m)
} }
@ -138,7 +138,7 @@ func TestJsonFile(t *testing.T) {
} }
fmt.Println("files_test_dup.json written") fmt.Println("files_test_dup.json written")
err = am.JsonFileIndent("files_test_indent.json","", " ") err = am.JsonFileIndent("files_test_indent.json", "", " ")
if err != nil { if err != nil {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }
@ -160,7 +160,7 @@ func TestXmlFile(t *testing.T) {
} }
fmt.Println("files_test_dup.xml written") fmt.Println("files_test_dup.xml written")
err = am.XmlFileIndent("files_test_indent.xml","", " ") err = am.XmlFileIndent("files_test_indent.xml", "", " ")
if err != nil { if err != nil {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }

View File

@ -6,7 +6,6 @@
// Wrappers for end-to-end JSON to XML transformation and value manipulation. // Wrappers for end-to-end JSON to XML transformation and value manipulation.
package j2x package j2x
import ( import (
. "github.com/clbanning/mxj" . "github.com/clbanning/mxj"
"io" "io"

View File

@ -4,8 +4,8 @@ package j2x
import ( import (
"bytes" "bytes"
"io/ioutil"
"fmt" "fmt"
"io/ioutil"
"testing" "testing"
) )

View File

@ -27,4 +27,3 @@ func TestJ2X(t *testing.T) {
fmt.Println("j2x, m :", m) fmt.Println("j2x, m :", m)
fmt.Println("j2x, xml :", string(x)) fmt.Println("j2x, xml :", string(x))
} }

View File

@ -124,7 +124,7 @@ var JsonUseNumber bool
func NewMapJson(jsonVal []byte) (Map, error) { func NewMapJson(jsonVal []byte) (Map, error) {
// empty or nil begets empty // empty or nil begets empty
if len(jsonVal) == 0 { if len(jsonVal) == 0 {
m := make(map[string]interface{},0) m := make(map[string]interface{}, 0)
return m, nil return m, nil
} }
// handle a goofy case ... // handle a goofy case ...

View File

@ -132,7 +132,7 @@ func TestValuesForKey(t *testing.T) {
if sserr != nil { if sserr != nil {
t.Fatal("sserr:", sserr.Error()) t.Fatal("sserr:", sserr.Error())
} }
for _, v := range ss { // should be len(ss) == 0 for _, v := range ss { // should be len(ss) == 0
fmt.Println("... ss.v:", v) fmt.Println("... ss.v:", v)
} }
} }
@ -189,7 +189,7 @@ func TestValuesForPath(t *testing.T) {
} }
} }
func TestValuesForNotKey( t *testing.T) { func TestValuesForNotKey(t *testing.T) {
fmt.Println("ValuesForNotKey ...") fmt.Println("ValuesForNotKey ...")
m, merr := NewMapXml(doc1) m, merr := NewMapXml(doc1)
if merr != nil { if merr != nil {
@ -209,7 +209,7 @@ func TestValuesForNotKey( t *testing.T) {
if sserr != nil { if sserr != nil {
t.Fatal("sserr:", sserr.Error()) t.Fatal("sserr:", sserr.Error())
} }
for _, v := range ss { // expect len(ss) == 0 for _, v := range ss { // expect len(ss) == 0
fmt.Println("... ss.v:", v) fmt.Println("... ss.v:", v)
} }

View File

@ -23,7 +23,7 @@ type LeafNode struct {
// LeafNodes - returns an array of all LeafNode values for the Map. // LeafNodes - returns an array of all LeafNode values for the Map.
// The option no_attr argument suppresses attribute values (keys with prepended hyphen, '-') // The option no_attr argument suppresses attribute values (keys with prepended hyphen, '-')
// as well as the "#text" key for the associated simple element value. // as well as the "#text" key for the associated simple element value.
func (mv Map)LeafNodes(no_attr ...bool) []LeafNode { func (mv Map) LeafNodes(no_attr ...bool) []LeafNode {
var a bool var a bool
if len(no_attr) == 1 { if len(no_attr) == 1 {
a = no_attr[0] a = no_attr[0]
@ -64,8 +64,8 @@ func getLeafNodes(path, node string, mv interface{}, l *[]LeafNode, noattr bool)
// LeafPaths - all paths that terminate in LeafNode values. // LeafPaths - all paths that terminate in LeafNode values.
func (mv Map) LeafPaths(no_attr ...bool) []string { func (mv Map) LeafPaths(no_attr ...bool) []string {
ln := mv.LeafNodes() ln := mv.LeafNodes()
ss := make([]string,len(ln)) ss := make([]string, len(ln))
for i := 0 ; i < len(ln); i++ { for i := 0; i < len(ln); i++ {
ss[i] = ln[i].Path ss[i] = ln[i].Path
} }
return ss return ss
@ -74,8 +74,8 @@ func (mv Map) LeafPaths(no_attr ...bool) []string {
// LeafValues - all terminal values in the Map. // LeafValues - all terminal values in the Map.
func (mv Map) LeafValues(no_attr ...bool) []interface{} { func (mv Map) LeafValues(no_attr ...bool) []interface{} {
ln := mv.LeafNodes() ln := mv.LeafNodes()
vv := make([]interface{},len(ln)) vv := make([]interface{}, len(ln))
for i := 0 ; i < len(ln); i++ { for i := 0; i < len(ln); i++ {
vv[i] = ln[i].Value vv[i] = ln[i].Value
} }
return vv return vv

View File

@ -72,7 +72,6 @@ func TestLeafNodes(t *testing.T) {
fmt.Printf("%#v\n", v) fmt.Printf("%#v\n", v)
} }
xmldata2 := []byte(` xmldata2 := []byte(`
<doc> <doc>
<item num="2" color="blue">Item 2 is blue</item> <item num="2" color="blue">Item 2 is blue</item>

View File

@ -38,7 +38,7 @@ func (mv Map) Old() map[string]interface{} {
// be represented as a map[string]interface{} value. // be represented as a map[string]interface{} value.
func (mv Map) Copy() (Map, error) { func (mv Map) Copy() (Map, error) {
// this is the poor-man's deep copy // this is the poor-man's deep copy
// not efficient, but it works // not efficient, but it works
j, jerr := mv.Json() j, jerr := mv.Json()
// must handle, we don't know how mv got built // must handle, we don't know how mv got built
if jerr != nil { if jerr != nil {

View File

@ -13,8 +13,8 @@ func TestMap(t *testing.T) {
m := New() m := New()
m["key"] = interface{}("value") m["key"] = interface{}("value")
v := map[string]interface{}{ "bool":true, "float":3.14159, "string":"Now is the time" } v := map[string]interface{}{"bool": true, "float": 3.14159, "string": "Now is the time"}
vv := []interface{}{ 3.1415962535, false, "for all good men" } vv := []interface{}{3.1415962535, false, "for all good men"}
v["listkey"] = interface{}(vv) v["listkey"] = interface{}(vv)
m["newkey"] = interface{}(v) m["newkey"] = interface{}(v)
@ -23,14 +23,14 @@ func TestMap(t *testing.T) {
o := interface{}(m.Old()) o := interface{}(m.Old())
switch o.(type) { switch o.(type) {
case map[string]interface{}: case map[string]interface{}:
// do nothing // do nothing
default: default:
t.Fatal("invalid type for m.Old()") t.Fatal("invalid type for m.Old()")
} }
m, _ = NewMapXml([]byte(`<doc><tag><sub_tag1>Hello</sub_tag1><sub_tag2>World</sub_tag2></tag></doc>`)) m, _ = NewMapXml([]byte(`<doc><tag><sub_tag1>Hello</sub_tag1><sub_tag2>World</sub_tag2></tag></doc>`))
fmt.Println("TestMap, m_fromXML:",m) fmt.Println("TestMap, m_fromXML:", m)
fmt.Println("TestMap, StringIndent:", m.StringIndent()) fmt.Println("TestMap, StringIndent:", m.StringIndent())
mm, _ := m.Copy() mm, _ := m.Copy()

View File

@ -22,9 +22,9 @@ import (
"strings" "strings"
) )
// (Map)NewMap - create a new Map from data in the current Map. // (Map)NewMap - create a new Map from data in the current Map.
// 'keypairs' are key mappings "oldKey:newKey" and specify that the current value of 'oldKey' // 'keypairs' are key mappings "oldKey:newKey" and specify that the current value of 'oldKey'
// should be the value for 'newKey' in the returned Map. // should be the value for 'newKey' in the returned Map.
// - 'oldKey' supports dot-notation as described for (Map)ValuesForPath() // - 'oldKey' supports dot-notation as described for (Map)ValuesForPath()
// - 'newKey' supports dot-notation but with no wildcards, '*', or indexed arrays // - 'newKey' supports dot-notation but with no wildcards, '*', or indexed arrays
// - "oldKey" is shorthand for for the keypair value "oldKey:oldKey" // - "oldKey" is shorthand for for the keypair value "oldKey:oldKey"
@ -32,7 +32,7 @@ import (
// - if 'oldKey' does not exist in the current Map, it is not written to the new Map. // - if 'oldKey' does not exist in the current Map, it is not written to the new Map.
// "null" is not supported unless it is the current Map. // "null" is not supported unless it is the current Map.
// - see newmap_test.go for several syntax examples // - see newmap_test.go for several syntax examples
// //
// NOTE: mv.NewMap() == mxj.New(). // NOTE: mv.NewMap() == mxj.New().
func (mv Map) NewMap(keypairs ...string) (Map, error) { func (mv Map) NewMap(keypairs ...string) (Map, error) {
n := make(map[string]interface{}, 0) n := make(map[string]interface{}, 0)
@ -67,7 +67,7 @@ func (mv Map) NewMap(keypairs ...string) (Map, error) {
return n, errors.New("newKey value cannot contain indexed arrays - " + v) return n, errors.New("newKey value cannot contain indexed arrays - " + v)
} }
if oldKey == "" || newKey == "" { if oldKey == "" || newKey == "" {
return n, errors.New("oldKey or newKey is not specified - " + v) return n, errors.New("oldKey or newKey is not specified - " + v)
} }
// get oldKey value // get oldKey value
@ -125,7 +125,7 @@ func addNewVal(n *map[string]interface{}, path []string, val []interface{}) {
// The placement of the next value in the array is dependent // The placement of the next value in the array is dependent
// on the sequence of members - could land on a map or a nil // on the sequence of members - could land on a map or a nil
// value first. TODO: how to test this. // value first. TODO: how to test this.
a := make([]interface{},0) a := make([]interface{}, 0)
var foundmap bool var foundmap bool
for _, vv := range m[k].([]interface{}) { for _, vv := range m[k].([]interface{}) {
switch vv.(type) { switch vv.(type) {
@ -135,7 +135,7 @@ func addNewVal(n *map[string]interface{}, path []string, val []interface{}) {
continue continue
} }
nm = make(map[string]interface{}, 0) nm = make(map[string]interface{}, 0)
a = append(a,interface{}(nm)) a = append(a, interface{}(nm))
foundmap = true foundmap = true
case map[string]interface{}: case map[string]interface{}:
if foundmap { // use the first one in array if foundmap { // use the first one in array
@ -151,7 +151,7 @@ func addNewVal(n *map[string]interface{}, path []string, val []interface{}) {
} }
// no map found in array // no map found in array
if !foundmap { if !foundmap {
nm = make(map[string]interface{},0) nm = make(map[string]interface{}, 0)
a = append(a, interface{}(nm)) a = append(a, interface{}(nm))
} }
m[k] = interface{}(a) // must insert in map m[k] = interface{}(a) // must insert in map
@ -178,6 +178,6 @@ func addNewVal(n *map[string]interface{}, path []string, val []interface{}) {
default: // v exists:string, float64, bool, map[string]interface, etc. default: // v exists:string, float64, bool, map[string]interface, etc.
a := make([]interface{}, 0) a := make([]interface{}, 0)
a = append(a, v, newVal) a = append(a, v, newVal)
m[k] =interface{}(a) m[k] = interface{}(a)
} }
} }

View File

@ -1,9 +1,9 @@
package mxj package mxj
import ( import (
"io"
"bytes" "bytes"
"fmt" "fmt"
"io"
"testing" "testing"
) )
@ -18,7 +18,7 @@ func TestNewMap(t *testing.T) {
m, _ := NewMapJson(j) m, _ := NewMapJson(j)
fmt.Printf("m: %#v\n", m) fmt.Printf("m: %#v\n", m)
fmt.Println("\n",`eval - m.NewMap("A:AA", "B:BB", "C:cc", "D:help")`) fmt.Println("\n", `eval - m.NewMap("A:AA", "B:BB", "C:cc", "D:help")`)
n, err := m.NewMap("A:AA", "B:BB", "C:cc", "D:help") n, err := m.NewMap("A:AA", "B:BB", "C:cc", "D:help")
if err != nil { if err != nil {
fmt.Println("err:", err.Error()) fmt.Println("err:", err.Error())
@ -26,11 +26,11 @@ func TestNewMap(t *testing.T) {
j, _ = n.Json() j, _ = n.Json()
fmt.Println("n.Json():", string(j)) fmt.Println("n.Json():", string(j))
x, _ := n.Xml() x, _ := n.Xml()
fmt.Println("n.Xml():\n",string(x)) fmt.Println("n.Xml():\n", string(x))
x, _ = n.XmlIndent("", " ") x, _ = n.XmlIndent("", " ")
fmt.Println("n.XmlIndent():\n",string(x)) fmt.Println("n.XmlIndent():\n", string(x))
fmt.Println("\n",`eval - m.NewMap("A:AA.A", "B:AA.B", "C:AA.B.cc", "D:hello.help")`) fmt.Println("\n", `eval - m.NewMap("A:AA.A", "B:AA.B", "C:AA.B.cc", "D:hello.help")`)
n, err = m.NewMap("A:AA.A", "B:AA.B", "C:AA.B.cc", "D:hello.help") n, err = m.NewMap("A:AA.A", "B:AA.B", "C:AA.B.cc", "D:hello.help")
if err != nil { if err != nil {
fmt.Println("err:", err.Error()) fmt.Println("err:", err.Error())
@ -38,12 +38,12 @@ func TestNewMap(t *testing.T) {
j, _ = n.Json() j, _ = n.Json()
fmt.Println("n.Json():", string(j)) fmt.Println("n.Json():", string(j))
x, _ = n.Xml() x, _ = n.Xml()
fmt.Println("n.Xml():\n",string(x)) fmt.Println("n.Xml():\n", string(x))
x, _ = n.XmlIndent("", " ") x, _ = n.XmlIndent("", " ")
fmt.Println("n.XmlIndent():\n",string(x)) fmt.Println("n.XmlIndent():\n", string(x))
var keypairs = []string{ "A:xml.AA", "B:xml.AA.hello.again", "C:xml.AA", "D:xml.AA.hello.help" } var keypairs = []string{"A:xml.AA", "B:xml.AA.hello.again", "C:xml.AA", "D:xml.AA.hello.help"}
fmt.Println("\n",`eval - m.NewMap keypairs:`,keypairs) fmt.Println("\n", `eval - m.NewMap keypairs:`, keypairs)
n, err = m.NewMap(keypairs...) n, err = m.NewMap(keypairs...)
if err != nil { if err != nil {
fmt.Println("err:", err.Error()) fmt.Println("err:", err.Error())
@ -51,9 +51,9 @@ func TestNewMap(t *testing.T) {
j, _ = n.Json() j, _ = n.Json()
fmt.Println("n.Json():", string(j)) fmt.Println("n.Json():", string(j))
x, _ = n.Xml() x, _ = n.Xml()
fmt.Println("n.Xml():\n",string(x)) fmt.Println("n.Xml():\n", string(x))
x, _ = n.XmlIndent("", " ") x, _ = n.XmlIndent("", " ")
fmt.Println("n.XmlIndent():\n",string(x)) fmt.Println("n.XmlIndent():\n", string(x))
} }
// Need to normalize from an XML stream the values for "netid" and "idnet". // Need to normalize from an XML stream the values for "netid" and "idnet".

View File

@ -30,7 +30,7 @@ func TestSeqNumHeader(t *testing.T) {
} }
func TestSeqNum(t *testing.T) { func TestSeqNum(t *testing.T) {
IncludeTagSeqNum( true ) IncludeTagSeqNum(true)
m, err := NewMapXml(seqdata1, Cast) m, err := NewMapXml(seqdata1, Cast)
if err != nil { if err != nil {
@ -48,5 +48,5 @@ func TestSeqNum(t *testing.T) {
j, _ = m.JsonIndent("", " ") j, _ = m.JsonIndent("", " ")
fmt.Println(string(j)) fmt.Println(string(j))
IncludeTagSeqNum( false ) IncludeTagSeqNum(false)
} }

View File

@ -11,29 +11,29 @@ func TestStructHeader(t *testing.T) {
func TestNewMapStruct(t *testing.T) { func TestNewMapStruct(t *testing.T) {
type str struct { type str struct {
IntVal int `json:"int"` IntVal int `json:"int"`
StrVal string `json:"str"` StrVal string `json:"str"`
FloatVal float64 `json:"float"` FloatVal float64 `json:"float"`
BoolVal bool `json:"bool"` BoolVal bool `json:"bool"`
private string private string
} }
s := str{ IntVal:4, StrVal:"now's the time", FloatVal:3.14159, BoolVal:true, private:"It's my party" } s := str{IntVal: 4, StrVal: "now's the time", FloatVal: 3.14159, BoolVal: true, private: "It's my party"}
m, merr := NewMapStruct(s) m, merr := NewMapStruct(s)
if merr != nil { if merr != nil {
t.Fatal("merr:", merr.Error()) t.Fatal("merr:", merr.Error())
} }
fmt.Printf("NewMapStruct, s: %#v\n",s) fmt.Printf("NewMapStruct, s: %#v\n", s)
fmt.Printf("NewMapStruct, m: %#v\n",m) fmt.Printf("NewMapStruct, m: %#v\n", m)
m, merr = NewMapStruct(s) m, merr = NewMapStruct(s)
if merr != nil { if merr != nil {
t.Fatal("merr:", merr.Error()) t.Fatal("merr:", merr.Error())
} }
fmt.Printf("NewMapStruct, s: %#v\n",s) fmt.Printf("NewMapStruct, s: %#v\n", s)
fmt.Printf("NewMapStruct, m: %#v\n",m) fmt.Printf("NewMapStruct, m: %#v\n", m)
} }
func TestNewMapStructError(t *testing.T) { func TestNewMapStructError(t *testing.T) {
@ -43,38 +43,38 @@ func TestNewMapStructError(t *testing.T) {
t.Fatal("NewMapStructError, merr is nil") t.Fatal("NewMapStructError, merr is nil")
} }
fmt.Println("NewMapStructError, merr:",merr.Error()) fmt.Println("NewMapStructError, merr:", merr.Error())
} }
func TestStruct(t *testing.T) { func TestStruct(t *testing.T) {
type str struct { type str struct {
IntVal int `json:"int"` IntVal int `json:"int"`
StrVal string `json:"str"` StrVal string `json:"str"`
FloatVal float64 `json:"float"` FloatVal float64 `json:"float"`
BoolVal bool `json:"bool"` BoolVal bool `json:"bool"`
private string private string
} }
var s str var s str
m := Map{ "int":4, "str":"now's the time", "float":3.14159, "bool":true, "private":"Somewhere over the rainbow" } m := Map{"int": 4, "str": "now's the time", "float": 3.14159, "bool": true, "private": "Somewhere over the rainbow"}
mverr := m.Struct(&s) mverr := m.Struct(&s)
if mverr != nil { if mverr != nil {
t.Fatal("mverr:", mverr.Error()) t.Fatal("mverr:", mverr.Error())
} }
fmt.Printf("Struct, m: %#v\n",m) fmt.Printf("Struct, m: %#v\n", m)
fmt.Printf("Struct, s: %#v\n",s) fmt.Printf("Struct, s: %#v\n", s)
} }
func TestStructError(t *testing.T) { func TestStructError(t *testing.T) {
type str struct { type str struct {
IntVal int `json:"int"` IntVal int `json:"int"`
StrVal string `json:"str"` StrVal string `json:"str"`
FloatVal float64 `json:"float"` FloatVal float64 `json:"float"`
BoolVal bool `json:"bool"` BoolVal bool `json:"bool"`
} }
var s str var s str
mv := Map{ "int":4, "str":"now's the time", "float":3.14159, "bool":true } mv := Map{"int": 4, "str": "now's the time", "float": 3.14159, "bool": true}
mverr := mv.Struct(s) mverr := mv.Struct(s)
if mverr == nil { if mverr == nil {
@ -82,4 +82,3 @@ func TestStructError(t *testing.T) {
} }
fmt.Println("StructError, mverr:", mverr.Error()) fmt.Println("StructError, mverr:", mverr.Error())
} }

View File

@ -11,7 +11,6 @@ func TestUVHeader(t *testing.T) {
fmt.Println("\n---------------- updatevalues_test.go ...\n") fmt.Println("\n---------------- updatevalues_test.go ...\n")
} }
func TestUpdateValuesForPath_Author(t *testing.T) { func TestUpdateValuesForPath_Author(t *testing.T) {
m, merr := NewMapXml(doc1) m, merr := NewMapXml(doc1)
if merr != nil { if merr != nil {
@ -71,7 +70,7 @@ func TestUpdateValuesForPath_Author(t *testing.T) {
fmt.Println("m:", m) fmt.Println("m:", m)
fmt.Println("m.UpdateValuesForPath(mm, \"*\")") fmt.Println("m.UpdateValuesForPath(mm, \"*\")")
mm, _ := NewMapXml(doc1) mm, _ := NewMapXml(doc1)
n, err = m.UpdateValuesForPath(mm, "*") n, err = m.UpdateValuesForPath(mm, "*")
if err != nil { if err != nil {
t.Fatal("err:", err.Error()) t.Fatal("err:", err.Error())
@ -83,7 +82,7 @@ func TestUpdateValuesForPath_Author(t *testing.T) {
var newDoc = []byte(`<tag color="green" shape="square">simple element</tag>`) var newDoc = []byte(`<tag color="green" shape="square">simple element</tag>`)
m, merr = NewMapXml(newDoc) m, merr = NewMapXml(newDoc)
if merr != nil { if merr != nil {
t.Fatal("merr:",merr.Error()) t.Fatal("merr:", merr.Error())
} }
fmt.Println("\nnewDoc:", string(newDoc)) fmt.Println("\nnewDoc:", string(newDoc))
fmt.Println("m:", m) fmt.Println("m:", m)
@ -94,29 +93,29 @@ func TestUpdateValuesForPath_Author(t *testing.T) {
n, _ = m.UpdateValuesForPath("#text:simple element again", "*") n, _ = m.UpdateValuesForPath("#text:simple element again", "*")
fmt.Println("n:", n, "m:", m) fmt.Println("n:", n, "m:", m)
/* /*
fmt.Println("UpdateValuesForPath, doc.books.book, title:The Recognitions : NoBook") fmt.Println("UpdateValuesForPath, doc.books.book, title:The Recognitions : NoBook")
n, err = m.UpdateValuesForPath("NoBook", "doc.books.book", "title:The Recognitions") n, err = m.UpdateValuesForPath("NoBook", "doc.books.book", "title:The Recognitions")
if err != nil { if err != nil {
t.Fatal("err:", err.Error()) t.Fatal("err:", err.Error())
} }
fmt.Println(n, "updates") fmt.Println(n, "updates")
ss, _ = m.ValuesForPath("doc.books.book") ss, _ = m.ValuesForPath("doc.books.book")
for _, v := range ss { for _, v := range ss {
fmt.Println("v:", v) fmt.Println("v:", v)
} }
fmt.Println("UpdateValuesForPath, doc.books.book.title -seq=3: The Blood Oranges") fmt.Println("UpdateValuesForPath, doc.books.book.title -seq=3: The Blood Oranges")
n, err = m.UpdateValuesForPath("The Blood Oranges", "doc.books.book.title", "-seq:3") n, err = m.UpdateValuesForPath("The Blood Oranges", "doc.books.book.title", "-seq:3")
if err != nil { if err != nil {
t.Fatal("err:", err.Error()) t.Fatal("err:", err.Error())
} }
fmt.Println(n, "updates") fmt.Println(n, "updates")
ss, _ = m.ValuesForPath("doc.books.book.title") ss, _ = m.ValuesForPath("doc.books.book.title")
for _, v := range ss { for _, v := range ss {
fmt.Println("v:", v) fmt.Println("v:", v)
} }
*/ */
} }
var authorDoc = []byte(` var authorDoc = []byte(`
@ -160,7 +159,7 @@ var authorDoc = []byte(`
func TestAuthorDoc(t *testing.T) { func TestAuthorDoc(t *testing.T) {
m, merr := NewMapXml(authorDoc) m, merr := NewMapXml(authorDoc)
if merr != nil { if merr != nil {
t.Fatal("merr:", merr.Error()) t.Fatal("merr:", merr.Error())
} }
fmt.Println(m.StringIndent()) fmt.Println(m.StringIndent())
@ -175,7 +174,7 @@ func TestAuthorDoc(t *testing.T) {
fmt.Println("m.UpdateValuesForPath(newVal, path, oldVal)") fmt.Println("m.UpdateValuesForPath(newVal, path, oldVal)")
path := m.PathForKeyShortest("date") path := m.PathForKeyShortest("date")
v,_ := m.ValuesForPath(path) v, _ := m.ValuesForPath(path)
var counter int var counter int
for _, vv := range v { for _, vv := range v {
oldVal := "date:" + vv.(string) oldVal := "date:" + vv.(string)
@ -186,5 +185,3 @@ func TestAuthorDoc(t *testing.T) {
fmt.Println(counter, "updates") fmt.Println(counter, "updates")
fmt.Println(m.StringIndent()) fmt.Println(m.StringIndent())
} }

View File

@ -38,7 +38,7 @@ func XmlToJson(xmlVal []byte, safeEncoding ...bool) ([]byte, error) {
func XmlToJsonWriter(xmlVal []byte, jsonWriter io.Writer, safeEncoding ...bool) ([]byte, error) { func XmlToJsonWriter(xmlVal []byte, jsonWriter io.Writer, safeEncoding ...bool) ([]byte, error) {
m, err := NewMapXml(xmlVal) m, err := NewMapXml(xmlVal)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return m.JsonWriterRaw(jsonWriter, safeEncoding...) return m.JsonWriterRaw(jsonWriter, safeEncoding...)
} }

View File

@ -79,7 +79,7 @@ func TestNewMapXmlReader(t *testing.T) {
// --------------------- Xml() and XmlWriter() test cases ------------------- // --------------------- Xml() and XmlWriter() test cases -------------------
func TestXml_1(t *testing.T) { func TestXml_1(t *testing.T) {
mv := Map{"tag1": "some data", "tag2": "more data", "boolean": true, "float": 3.14159625, "null":nil} mv := Map{"tag1": "some data", "tag2": "more data", "boolean": true, "float": 3.14159625, "null": nil}
x, err := mv.Xml() x, err := mv.Xml()
if err != nil { if err != nil {
@ -91,8 +91,8 @@ func TestXml_1(t *testing.T) {
} }
func TestXml_2(t *testing.T) { func TestXml_2(t *testing.T) {
a := []interface{}{ "string", true, 36.4 } a := []interface{}{"string", true, 36.4}
mv := Map{"array": a } mv := Map{"array": a}
x, err := mv.Xml() x, err := mv.Xml()
if err != nil { if err != nil {
@ -104,8 +104,8 @@ func TestXml_2(t *testing.T) {
} }
func TestXml_3(t *testing.T) { func TestXml_3(t *testing.T) {
a := []interface{}{ "string", true, 36.4 } a := []interface{}{"string", true, 36.4}
mv := Map{"array": []interface{}{a, "string2"} } mv := Map{"array": []interface{}{a, "string2"}}
x, err := mv.Xml() x, err := mv.Xml()
if err != nil { if err != nil {
@ -117,8 +117,8 @@ func TestXml_3(t *testing.T) {
} }
func TestXml_4(t *testing.T) { func TestXml_4(t *testing.T) {
a := []interface{}{ "string", true, 36.4 } a := []interface{}{"string", true, 36.4}
mv := Map{"array": map[string]interface{}{ "innerkey": []interface{}{a, "string2"} } } mv := Map{"array": map[string]interface{}{"innerkey": []interface{}{a, "string2"}}}
x, err := mv.Xml() x, err := mv.Xml()
if err != nil { if err != nil {
@ -130,8 +130,8 @@ func TestXml_4(t *testing.T) {
} }
func TestXml_5(t *testing.T) { func TestXml_5(t *testing.T) {
a := []interface{}{ "string", true, 36.4 } a := []interface{}{"string", true, 36.4}
mv := Map{"array": []interface{}{ map[string]interface{}{ "innerkey": []interface{}{a, "string2"} }, map[string]interface{}{"some":"more"} } } mv := Map{"array": []interface{}{map[string]interface{}{"innerkey": []interface{}{a, "string2"}}, map[string]interface{}{"some": "more"}}}
x, err := mv.Xml() x, err := mv.Xml()
if err != nil { if err != nil {
@ -148,10 +148,10 @@ func TestXmlWriter(t *testing.T) {
raw, err := mv.XmlWriterRaw(w, "myRootTag") raw, err := mv.XmlWriterRaw(w, "myRootTag")
if err != nil { if err != nil {
t.Fatal("err:",err.Error()) t.Fatal("err:", err.Error())
} }
b := make([]byte,w.Len()) b := make([]byte, w.Len())
_, err = w.Read(b) _, err = w.Read(b)
if err != nil { if err != nil {
t.Fatal("err:", err.Error()) t.Fatal("err:", err.Error())

View File

@ -11,7 +11,7 @@ checkgopath:
@if [ ! -d ${MINIOPATH} ]; then echo "Project not found in $GOPATH, please follow instructions provided at https://github.com/Minio-io/minio/blob/master/CONTRIBUTING.md#setup-your-minio-github-repository" && exit 1; fi @if [ ! -d ${MINIOPATH} ]; then echo "Project not found in $GOPATH, please follow instructions provided at https://github.com/Minio-io/minio/blob/master/CONTRIBUTING.md#setup-your-minio-github-repository" && exit 1; fi
getdeps: checkdeps checkgopath getdeps: checkdeps checkgopath
@go get github.com/tools/godep && echo "Installed godep:" @go get github.com/minio-io/godep && echo "Installed godep:"
@go get github.com/golang/lint/golint && echo "Installed golint:" @go get github.com/golang/lint/golint && echo "Installed golint:"
@go get golang.org/x/tools/cmd/vet && echo "Installed vet:" @go get golang.org/x/tools/cmd/vet && echo "Installed vet:"
@go get github.com/fzipp/gocyclo && echo "Installed gocyclo:" @go get github.com/fzipp/gocyclo && echo "Installed gocyclo:"