2024-06-28 14:38:20 +01:00
|
|
|
package stations
|
|
|
|
|
|
|
|
import (
|
2024-06-29 21:54:32 +01:00
|
|
|
"bytes"
|
|
|
|
"encoding/xml"
|
|
|
|
"fmt"
|
2024-06-28 14:38:20 +01:00
|
|
|
|
2024-06-29 21:54:32 +01:00
|
|
|
"git.fjla.uk/owlboard/go-types/pkg/database"
|
|
|
|
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
|
2024-06-28 14:38:20 +01:00
|
|
|
)
|
2024-06-29 21:54:32 +01:00
|
|
|
|
|
|
|
// Parses n number of XML byte arrays
|
|
|
|
func parseData(data ...[]byte) ([]database.Station, error) {
|
|
|
|
var stations []upstreamApi.Station
|
|
|
|
for _, d := range data {
|
|
|
|
parsedStations, err := parseXML(d)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
stations = append(stations, parsedStations...)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(stations)
|
|
|
|
return nil, nil
|
|
|
|
// Transform from upstreamApi.Station to database.Station
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parses XML and converts to struct
|
|
|
|
func parseXML(data []byte) ([]upstreamApi.Station, error) {
|
|
|
|
var stationList upstreamApi.StationList
|
|
|
|
|
|
|
|
reader := bytes.NewReader(data)
|
|
|
|
decoder := xml.NewDecoder(reader)
|
|
|
|
err := decoder.Decode(&stationList)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error parsing XML: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return stationList.Stations, nil
|
|
|
|
}
|