From 4b31ea924d1c326e8b912ae6091f40a5954d90ad Mon Sep 17 00:00:00 2001 From: jim teeuwen Date: Wed, 2 Nov 2011 16:50:45 +0100 Subject: [PATCH] gofix error --- document.go | 21 +++++++++++---------- entitymap.go | 3 +-- node.go | 3 +-- xmlx_test.go | 6 +++--- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/document.go b/document.go index f4d65d2..747ee21 100644 --- a/document.go +++ b/document.go @@ -25,6 +25,7 @@ package xmlx import ( + "errors" "os" "io" "io/ioutil" @@ -78,10 +79,10 @@ func (this *Document) SelectNodes(namespace, name string) []*Node { } // 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.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) } @@ -94,7 +95,7 @@ func (this *Document) LoadStream(r io.Reader) (err os.Error) { for { if tok, err = xp.Token(); err != nil { - if err == os.EOF { + if err == io.EOF { return nil } return err @@ -102,7 +103,7 @@ func (this *Document) LoadStream(r io.Reader) (err os.Error) { switch tt := tok.(type) { case xml.SyntaxError: - return os.NewError(tt.String()) + return errors.New(tt.Error()) case xml.CharData: ct.Value = strings.TrimSpace(string([]byte(tt))) 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. -func (this *Document) LoadBytes(d []byte) (err os.Error) { +func (this *Document) LoadBytes(d []byte) (err error) { return this.LoadStream(bytes.NewBuffer(d)) } // 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)) } // 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 if fd, err = os.Open(filename); err != nil { return @@ -170,7 +171,7 @@ func (this *Document) LoadFile(filename string) (err os.Error) { } // 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 if r, err = http.Get(uri); err != nil { return @@ -181,7 +182,7 @@ func (this *Document) LoadUri(uri string) (err os.Error) { } // 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) } @@ -206,7 +207,7 @@ func (this *Document) SaveString() string { return string(this.SaveBytes()) } func (this *Document) String() string { return string(this.SaveBytes()) } // 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()) return } diff --git a/entitymap.go b/entitymap.go index d17faec..e0aded2 100644 --- a/entitymap.go +++ b/entitymap.go @@ -17,7 +17,6 @@ package xmlx */ import ( - "os" "fmt" "utf8" "regexp" @@ -38,7 +37,7 @@ func EntityToUtf8(entity string) string { return "&" + entity[2:len(entity)-1] + ";" } - var err os.Error + var err error var num int entity = entity[2 : len(entity)-1] diff --git a/node.go b/node.go index ee0d228..52d33e6 100644 --- a/node.go +++ b/node.go @@ -5,7 +5,6 @@ package xmlx import ( - "os" "xml" "bytes" "fmt" @@ -45,7 +44,7 @@ func NewNode(tid byte) *Node { // This wraps the standard xml.Unmarshal function and supplies this particular // 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) } diff --git a/xmlx_test.go b/xmlx_test.go index ebbc806..aebdee0 100644 --- a/xmlx_test.go +++ b/xmlx_test.go @@ -10,7 +10,7 @@ func TestLoadLocal(t *testing.T) { doc := New() if err := doc.LoadFile("test.xml"); err != nil { - t.Error(err.String()) + t.Error(err.Error()) return } @@ -24,7 +24,7 @@ func TestWildcard(t *testing.T) { doc := New() if err := doc.LoadFile("test2.xml"); err != nil { - t.Error(err.String()) + t.Error(err.Error()) return } @@ -40,7 +40,7 @@ func _TestLoadRemote(t *testing.T) { doc := New() if err := doc.LoadUri("http://blog.golang.org/feeds/posts/default"); err != nil { - t.Error(err.String()) + t.Error(err.Error()) return }