mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
Added arrays to XMLProvider types for faster iteration
This commit is contained in:
32
providers/xmlprovider/helpers.go
Normal file
32
providers/xmlprovider/helpers.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package xmlprovider
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
|
||||
)
|
||||
|
||||
func UnmarshalFile[T any](filename string, data T) error {
|
||||
xmlFile, err := os.Open(filename)
|
||||
if err != nil {
|
||||
logging.Error(err, "Could not open file: "+filename)
|
||||
return err
|
||||
}
|
||||
defer xmlFile.Close()
|
||||
|
||||
logging.Info("Deserialization: " + filename)
|
||||
byteValue, err := io.ReadAll(xmlFile)
|
||||
if err != nil {
|
||||
logging.Error(err, "Could not read file: "+filename)
|
||||
return err
|
||||
}
|
||||
err = xml.Unmarshal(byteValue, &data)
|
||||
|
||||
if err != nil {
|
||||
logging.Error(err, "Could not unmarshal file: "+filename)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user