Skip to content

Commit b9b2f5c

Browse files
committed
gofmt -w
1 parent 7f969ea commit b9b2f5c

File tree

10 files changed

+839
-848
lines changed

10 files changed

+839
-848
lines changed

config/xml/x2j/goofy_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
func TestGoofy(t *testing.T) {
1010
var doc = `<xml><tag one="1" pi="3.1415962535" bool="true"/><tagJR key="value"/></xml>`
1111
type goofy struct {
12-
S string
12+
S string
1313
Sp *string
1414
}
1515
g := new(goofy)
@@ -19,21 +19,21 @@ func TestGoofy(t *testing.T) {
1919

2020
m, err := DocToMap(doc)
2121
if err != nil {
22-
fmt.Println("err:",err.Error())
22+
fmt.Println("err:", err.Error())
2323
return
2424
}
2525

2626
m["goofyVal"] = interface{}(g)
2727
m["byteVal"] = interface{}([]byte(`the aid of their country`))
2828
m["nilVal"] = interface{}(nil)
2929

30-
fmt.Println("\nTestGoofy ... MapToDoc:",m)
30+
fmt.Println("\nTestGoofy ... MapToDoc:", m)
3131
var v []byte
32-
v,err = json.Marshal(m)
32+
v, err = json.Marshal(m)
3333
if err != nil {
34-
fmt.Println("err:",err.Error())
34+
fmt.Println("err:", err.Error())
3535
}
36-
fmt.Println("v:",string(v))
36+
fmt.Println("v:", string(v))
3737

3838
type goofier struct {
3939
G *goofy
@@ -46,11 +46,10 @@ func TestGoofy(t *testing.T) {
4646
gg.N = nil
4747
m["goofierVal"] = interface{}(gg)
4848

49-
fmt.Println("\nTestGoofier ... MapToDoc:",m)
50-
v,err = json.Marshal(m)
49+
fmt.Println("\nTestGoofier ... MapToDoc:", m)
50+
v, err = json.Marshal(m)
5151
if err != nil {
52-
fmt.Println("err:",err.Error())
52+
fmt.Println("err:", err.Error())
5353
}
54-
fmt.Println("v:",string(v))
54+
fmt.Println("v:", string(v))
5555
}
56-

config/xml/x2j/reader2j.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ func ToJsonIndent(rdr io.Reader, recast ...bool) (string, error) {
7777
return string(b), nil
7878
}
7979

80-
8180
// ReaderValuesFromTagPath - io.Reader version of ValuesFromTagPath()
8281
func ReaderValuesFromTagPath(rdr io.Reader, path string, getAttrs ...bool) ([]interface{}, error) {
8382
var a bool
@@ -101,5 +100,3 @@ func ReaderValuesForTag(rdr io.Reader, tag string) ([]interface{}, error) {
101100

102101
return ValuesForKey(m, tag), nil
103102
}
104-
105-

config/xml/x2j/reader2j_test.go

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,76 @@ import (
99
var doc = `<entry><vars><foo>bar</foo><foo2><hello>world</hello></foo2></vars></entry>`
1010

1111
func TestToTree(t *testing.T) {
12-
fmt.Println("\nToTree - Read doc:",doc)
12+
fmt.Println("\nToTree - Read doc:", doc)
1313
rdr := bytes.NewBufferString(doc)
14-
n,err := ToTree(rdr)
14+
n, err := ToTree(rdr)
1515
if err != nil {
16-
fmt.Println("err:",err.Error())
16+
fmt.Println("err:", err.Error())
1717
}
1818
fmt.Println(n.WriteTree())
1919
}
2020

2121
func TestToMap(t *testing.T) {
22-
fmt.Println("\nToMap - Read doc:",doc)
22+
fmt.Println("\nToMap - Read doc:", doc)
2323
rdr := bytes.NewBufferString(doc)
24-
m,err := ToMap(rdr)
24+
m, err := ToMap(rdr)
2525
if err != nil {
26-
fmt.Println("err:",err.Error())
26+
fmt.Println("err:", err.Error())
2727
}
2828
fmt.Println(WriteMap(m))
2929
}
3030

3131
func TestToJson(t *testing.T) {
32-
fmt.Println("\nToJson - Read doc:",doc)
32+
fmt.Println("\nToJson - Read doc:", doc)
3333
rdr := bytes.NewBufferString(doc)
34-
s,err := ToJson(rdr)
34+
s, err := ToJson(rdr)
3535
if err != nil {
36-
fmt.Println("err:",err.Error())
36+
fmt.Println("err:", err.Error())
3737
}
38-
fmt.Println("json:",s)
38+
fmt.Println("json:", s)
3939
}
4040

4141
func TestToJsonIndent(t *testing.T) {
42-
fmt.Println("\nToJsonIndent - Read doc:",doc)
42+
fmt.Println("\nToJsonIndent - Read doc:", doc)
4343
rdr := bytes.NewBufferString(doc)
44-
s,err := ToJsonIndent(rdr)
44+
s, err := ToJsonIndent(rdr)
4545
if err != nil {
46-
fmt.Println("err:",err.Error())
46+
fmt.Println("err:", err.Error())
4747
}
48-
fmt.Println("json:",s)
48+
fmt.Println("json:", s)
4949
}
5050

5151
func TestBulkParser(t *testing.T) {
52-
s := doc + `<this><is>an</err>`+ doc
53-
fmt.Println("\nBulkParser (with error) - Read doc:",s)
52+
s := doc + `<this><is>an</err>` + doc
53+
fmt.Println("\nBulkParser (with error) - Read doc:", s)
5454
rdr := bytes.NewBufferString(s)
55-
err := XmlMsgsFromReader(rdr,phandler,ehandler)
55+
err := XmlMsgsFromReader(rdr, phandler, ehandler)
5656
if err != nil {
57-
fmt.Println("reader terminated:",err.Error())
57+
fmt.Println("reader terminated:", err.Error())
5858
}
5959
}
6060

6161
func phandler(m map[string]interface{}) bool {
62-
fmt.Println("phandler m:",m)
62+
fmt.Println("phandler m:", m)
6363
return true
6464
}
6565

6666
func ehandler(err error) bool {
67-
fmt.Println("ehandler err:",err.Error())
67+
fmt.Println("ehandler err:", err.Error())
6868
return true
6969
}
7070

7171
func TestBulkParserToJson(t *testing.T) {
72-
s := doc + `<this><is>an</err>`+ doc
73-
fmt.Println("\nBulkParser (with error) - Read doc:",s)
72+
s := doc + `<this><is>an</err>` + doc
73+
fmt.Println("\nBulkParser (with error) - Read doc:", s)
7474
rdr := bytes.NewBufferString(s)
75-
err := XmlMsgsFromReaderAsJson(rdr,phandlerj,ehandler)
75+
err := XmlMsgsFromReaderAsJson(rdr, phandlerj, ehandler)
7676
if err != nil {
77-
fmt.Println("reader terminated:",err.Error())
77+
fmt.Println("reader terminated:", err.Error())
7878
}
7979
}
8080

8181
func phandlerj(s string) bool {
82-
fmt.Println("phandlerj s:",s)
82+
fmt.Println("phandlerj s:", s)
8383
return true
8484
}
85-

config/xml/x2j/x2j.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
88
One useful function is:
99
10-
- Unmarshal(doc []byte, v interface{}) error
10+
- Unmarshal(doc []byte, v interface{}) error
1111
where v is a pointer to a variable of type 'map[string]interface{}', 'string', or
1212
any other type supported by xml.Unmarshal().
1313
14-
To retrieve a value for specific tag use:
14+
To retrieve a value for specific tag use:
1515
16-
- DocValue(doc, path string, attrs ...string) (interface{},error)
16+
- DocValue(doc, path string, attrs ...string) (interface{},error)
1717
- MapValue(m map[string]interface{}, path string, attr map[string]interface{}, recast ...bool) (interface{}, error)
1818
1919
The 'path' argument is a period-separated tag hierarchy - also known as dot-notation.
20-
It is the program's responsibility to cast the returned value to the proper type; possible
21-
types are the normal JSON unmarshaling types: string, float64, bool, []interface, map[string]interface{}.
20+
It is the program's responsibility to cast the returned value to the proper type; possible
21+
types are the normal JSON unmarshaling types: string, float64, bool, []interface, map[string]interface{}.
2222
2323
To retrieve all values associated with a tag occurring anywhere in the XML document use:
2424
@@ -31,7 +31,7 @@
3131
3232
Returned values should be one of map[string]interface, []interface{}, or string.
3333
34-
All the values assocated with a tag-path that may include one or more wildcard characters -
34+
All the values assocated with a tag-path that may include one or more wildcard characters -
3535
'*' - can also be retrieved using:
3636
3737
- ValuesFromTagPath(doc, path string, getAttrs ...bool) ([]interface{}, error)
@@ -42,7 +42,7 @@
4242
4343
NOTE: care should be taken when using "*" at the end of a path - i.e., "books.book.*". See
4444
the x2jpath_test.go case on how the wildcard returns all key values and collapses list values;
45-
the same message structure can load a []interface{} or a map[string]interface{} (or an interface{})
45+
the same message structure can load a []interface{} or a map[string]interface{} (or an interface{})
4646
value for a tag.
4747
4848
See the test cases in "x2jpath_test.go" and programs in "example" subdirectory for more.
@@ -83,7 +83,7 @@ import (
8383
// ...
8484
// x2j.X2jCharsetReader = charset.NewReader
8585
// s, err := x2j.DocToJson(doc)
86-
var X2jCharsetReader func(charset string, input io.Reader)(io.Reader, error)
86+
var X2jCharsetReader func(charset string, input io.Reader) (io.Reader, error)
8787

8888
type Node struct {
8989
dup bool // is member of a list
@@ -653,4 +653,3 @@ func ByteDocToTree(doc []byte) (*Node, error) {
653653

654654
return n, nil
655655
}
656-

config/xml/x2j/x2j_bulk.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
// Note: phandler() and ehandler() calls are blocking, so reading and processing of messages is serialized.
2323
// This means that you can stop reading the file on error or after processing a particular message.
2424
// To have reading and handling run concurrently, pass arguments to a go routine in handler and return true.
25-
func XmlMsgsFromFileAsJson(fname string, phandler func(string)(bool), ehandler func(error)(bool), recast ...bool) error {
25+
func XmlMsgsFromFileAsJson(fname string, phandler func(string) bool, ehandler func(error) bool, recast ...bool) error {
2626
var r bool
2727
if len(recast) == 1 {
2828
r = recast[0]
@@ -36,26 +36,26 @@ func XmlMsgsFromFileAsJson(fname string, phandler func(string)(bool), ehandler f
3636
return fherr
3737
}
3838
defer fh.Close()
39-
buf := make([]byte,fi.Size())
40-
_, rerr := fh.Read(buf)
39+
buf := make([]byte, fi.Size())
40+
_, rerr := fh.Read(buf)
4141
if rerr != nil {
4242
return rerr
4343
}
4444
doc := string(buf)
4545

4646
// xml.Decoder doesn't properly handle whitespace in some doc
47-
// see songTextString.xml test case ...
48-
reg,_ := regexp.Compile("[ \t\n\r]*<")
49-
doc = reg.ReplaceAllString(doc,"<")
47+
// see songTextString.xml test case ...
48+
reg, _ := regexp.Compile("[ \t\n\r]*<")
49+
doc = reg.ReplaceAllString(doc, "<")
5050
b := bytes.NewBufferString(doc)
5151

5252
for {
53-
s, serr := XmlBufferToJson(b,r)
53+
s, serr := XmlBufferToJson(b, r)
5454
if serr != nil && serr != io.EOF {
5555
if ok := ehandler(serr); !ok {
5656
// caused reader termination
5757
return serr
58-
}
58+
}
5959
}
6060
if s != "" {
6161
if ok := phandler(s); !ok {
@@ -72,13 +72,13 @@ func XmlMsgsFromFileAsJson(fname string, phandler func(string)(bool), ehandler f
7272
// XmlBufferToJson - process XML message from a bytes.Buffer
7373
// 'b' is the buffer
7474
// Optional argument 'recast' coerces values to float64 or bool where possible.
75-
func XmlBufferToJson(b *bytes.Buffer,recast ...bool) (string,error) {
75+
func XmlBufferToJson(b *bytes.Buffer, recast ...bool) (string, error) {
7676
var r bool
7777
if len(recast) == 1 {
7878
r = recast[0]
7979
}
8080

81-
n,err := XmlBufferToTree(b)
81+
n, err := XmlBufferToTree(b)
8282
if err != nil {
8383
return "", err
8484
}
@@ -99,19 +99,19 @@ func XmlBufferToJson(b *bytes.Buffer,recast ...bool) (string,error) {
9999
// Note: phandler() and ehandler() calls are blocking, so reading and processing of messages is serialized.
100100
// This means that you can stop reading the file on error or after processing a particular message.
101101
// To have reading and handling run concurrently, pass arguments to a go routine in handler and return true.
102-
func XmlMsgsFromReaderAsJson(rdr io.Reader, phandler func(string)(bool), ehandler func(error)(bool), recast ...bool) error {
102+
func XmlMsgsFromReaderAsJson(rdr io.Reader, phandler func(string) bool, ehandler func(error) bool, recast ...bool) error {
103103
var r bool
104104
if len(recast) == 1 {
105105
r = recast[0]
106106
}
107107

108108
for {
109-
s, serr := ToJson(rdr,r)
109+
s, serr := ToJson(rdr, r)
110110
if serr != nil && serr != io.EOF {
111111
if ok := ehandler(serr); !ok {
112112
// caused reader termination
113113
return serr
114-
}
114+
}
115115
}
116116
if s != "" {
117117
if ok := phandler(s); !ok {
@@ -124,4 +124,3 @@ func XmlMsgsFromReaderAsJson(rdr io.Reader, phandler func(string)(bool), ehandle
124124
}
125125
return nil
126126
}
127-

0 commit comments

Comments
 (0)