gofix error
This commit is contained in:
parent
0ecfd7fd99
commit
4b31ea924d
21
document.go
21
document.go
|
@ -25,6 +25,7 @@
|
||||||
package xmlx
|
package xmlx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -78,10 +79,10 @@ func (this *Document) SelectNodes(namespace, name string) []*Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the contents of this document from the supplied reader.
|
// Load the contents of this document from the supplied reader.
|
||||||
func (this *Document) LoadStream(r io.Reader) (err os.Error) {
|
func (this *Document) LoadStream(r io.Reader) (err error) {
|
||||||
xp := xml.NewParser(r)
|
xp := xml.NewParser(r)
|
||||||
xp.Entity = this.Entity
|
xp.Entity = this.Entity
|
||||||
xp.CharsetReader = func(enc string, input io.Reader) (io.Reader, os.Error) {
|
xp.CharsetReader = func(enc string, input io.Reader) (io.Reader, error) {
|
||||||
return charset.NewReader(enc, input)
|
return charset.NewReader(enc, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ func (this *Document) LoadStream(r io.Reader) (err os.Error) {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if tok, err = xp.Token(); err != nil {
|
if tok, err = xp.Token(); err != nil {
|
||||||
if err == os.EOF {
|
if err == io.EOF {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -102,7 +103,7 @@ func (this *Document) LoadStream(r io.Reader) (err os.Error) {
|
||||||
|
|
||||||
switch tt := tok.(type) {
|
switch tt := tok.(type) {
|
||||||
case xml.SyntaxError:
|
case xml.SyntaxError:
|
||||||
return os.NewError(tt.String())
|
return errors.New(tt.Error())
|
||||||
case xml.CharData:
|
case xml.CharData:
|
||||||
ct.Value = strings.TrimSpace(string([]byte(tt)))
|
ct.Value = strings.TrimSpace(string([]byte(tt)))
|
||||||
case xml.Comment:
|
case xml.Comment:
|
||||||
|
@ -149,17 +150,17 @@ func (this *Document) LoadStream(r io.Reader) (err os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the contents of this document from the supplied byte slice.
|
// Load the contents of this document from the supplied byte slice.
|
||||||
func (this *Document) LoadBytes(d []byte) (err os.Error) {
|
func (this *Document) LoadBytes(d []byte) (err error) {
|
||||||
return this.LoadStream(bytes.NewBuffer(d))
|
return this.LoadStream(bytes.NewBuffer(d))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the contents of this document from the supplied string.
|
// Load the contents of this document from the supplied string.
|
||||||
func (this *Document) LoadString(s string) (err os.Error) {
|
func (this *Document) LoadString(s string) (err error) {
|
||||||
return this.LoadStream(strings.NewReader(s))
|
return this.LoadStream(strings.NewReader(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the contents of this document from the supplied file.
|
// Load the contents of this document from the supplied file.
|
||||||
func (this *Document) LoadFile(filename string) (err os.Error) {
|
func (this *Document) LoadFile(filename string) (err error) {
|
||||||
var fd *os.File
|
var fd *os.File
|
||||||
if fd, err = os.Open(filename); err != nil {
|
if fd, err = os.Open(filename); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -170,7 +171,7 @@ func (this *Document) LoadFile(filename string) (err os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the contents of this document from the supplied uri.
|
// Load the contents of this document from the supplied uri.
|
||||||
func (this *Document) LoadUri(uri string) (err os.Error) {
|
func (this *Document) LoadUri(uri string) (err error) {
|
||||||
var r *http.Response
|
var r *http.Response
|
||||||
if r, err = http.Get(uri); err != nil {
|
if r, err = http.Get(uri); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -181,7 +182,7 @@ func (this *Document) LoadUri(uri string) (err os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the contents of this document to the supplied file.
|
// Save the contents of this document to the supplied file.
|
||||||
func (this *Document) SaveFile(path string) os.Error {
|
func (this *Document) SaveFile(path string) error {
|
||||||
return ioutil.WriteFile(path, this.SaveBytes(), 0600)
|
return ioutil.WriteFile(path, this.SaveBytes(), 0600)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +207,7 @@ func (this *Document) SaveString() string { return string(this.SaveBytes()) }
|
||||||
func (this *Document) String() string { return string(this.SaveBytes()) }
|
func (this *Document) String() string { return string(this.SaveBytes()) }
|
||||||
|
|
||||||
// Save the contents of this document to the supplied writer.
|
// Save the contents of this document to the supplied writer.
|
||||||
func (this *Document) SaveStream(w io.Writer) (err os.Error) {
|
func (this *Document) SaveStream(w io.Writer) (err error) {
|
||||||
_, err = w.Write(this.SaveBytes())
|
_, err = w.Write(this.SaveBytes())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ package xmlx
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"utf8"
|
"utf8"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -38,7 +37,7 @@ func EntityToUtf8(entity string) string {
|
||||||
return "&" + entity[2:len(entity)-1] + ";"
|
return "&" + entity[2:len(entity)-1] + ";"
|
||||||
}
|
}
|
||||||
|
|
||||||
var err os.Error
|
var err error
|
||||||
var num int
|
var num int
|
||||||
|
|
||||||
entity = entity[2 : len(entity)-1]
|
entity = entity[2 : len(entity)-1]
|
||||||
|
|
3
node.go
3
node.go
|
@ -5,7 +5,6 @@
|
||||||
package xmlx
|
package xmlx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"xml"
|
"xml"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -45,7 +44,7 @@ func NewNode(tid byte) *Node {
|
||||||
|
|
||||||
// This wraps the standard xml.Unmarshal function and supplies this particular
|
// This wraps the standard xml.Unmarshal function and supplies this particular
|
||||||
// node as the content to be unmarshalled.
|
// node as the content to be unmarshalled.
|
||||||
func (this *Node) Unmarshal(obj interface{}) os.Error {
|
func (this *Node) Unmarshal(obj interface{}) error {
|
||||||
return xml.Unmarshal(bytes.NewBuffer(this.Bytes()), obj)
|
return xml.Unmarshal(bytes.NewBuffer(this.Bytes()), obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ func TestLoadLocal(t *testing.T) {
|
||||||
doc := New()
|
doc := New()
|
||||||
|
|
||||||
if err := doc.LoadFile("test.xml"); err != nil {
|
if err := doc.LoadFile("test.xml"); err != nil {
|
||||||
t.Error(err.String())
|
t.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func TestWildcard(t *testing.T) {
|
||||||
doc := New()
|
doc := New()
|
||||||
|
|
||||||
if err := doc.LoadFile("test2.xml"); err != nil {
|
if err := doc.LoadFile("test2.xml"); err != nil {
|
||||||
t.Error(err.String())
|
t.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ func _TestLoadRemote(t *testing.T) {
|
||||||
doc := New()
|
doc := New()
|
||||||
|
|
||||||
if err := doc.LoadUri("http://blog.golang.org/feeds/posts/default"); err != nil {
|
if err := doc.LoadUri("http://blog.golang.org/feeds/posts/default"); err != nil {
|
||||||
t.Error(err.String())
|
t.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue