Add dump feature, enhance code quality (#1)

This commit is contained in:
T.v.Dein
2025-10-16 12:24:47 +02:00
committed by GitHub
parent d9ed4dee10
commit 6099806e22
10 changed files with 125 additions and 423 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/xml"
"fmt"
"io"
"log"
"path"
)
@@ -34,8 +35,8 @@ func (p *Book) Files() []string {
}
// Close close file reader
func (p *Book) Close() {
p.fd.Close()
func (p *Book) Close() error {
return p.fd.Close()
}
// -----------------------------------------------------------------------------
@@ -48,7 +49,13 @@ func (p *Book) readXML(n string, v interface{}) error {
if err != nil {
return nil
}
defer fd.Close()
defer func() {
if err := fd.Close(); err != nil {
log.Fatal(err)
}
}()
dec := xml.NewDecoder(fd)
if err := dec.Decode(v); err != nil {
@@ -63,7 +70,11 @@ func (p *Book) readBytes(n string) ([]byte, error) {
if err != nil {
return nil, nil
}
defer fd.Close()
defer func() {
if err := fd.Close(); err != nil {
log.Fatal(err)
}
}()
data, err := io.ReadAll(fd)
if err != nil {