timetable-mgr/stations/parse.go
Fred Boniface cd0f5c7003
All checks were successful
Go Test / test (push) Successful in 26s
Add stations modile
2024-06-29 21:54:32 +01:00

41 lines
908 B
Go

package stations
import (
"bytes"
"encoding/xml"
"fmt"
"git.fjla.uk/owlboard/go-types/pkg/database"
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
)
// 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
}