Fix parsing errors where 'CIF_speed' is not defined

This commit is contained in:
Fred Boniface 2023-07-21 09:36:23 +01:00
parent 9526f7da9d
commit 849f23b507
4 changed files with 14 additions and 5 deletions

View File

@ -3,7 +3,7 @@ module git.fjla.uk/owlboard/mq-client
go 1.19
require (
git.fjla.uk/owlboard/go-types v0.0.0-20230720203835-cf2b2d98e86a
git.fjla.uk/owlboard/go-types v0.0.0-20230721082911-9a574276d572
github.com/go-stomp/stomp/v3 v3.0.5
go.mongodb.org/mongo-driver v1.12.0
go.uber.org/zap v1.24.0

View File

@ -28,6 +28,10 @@ git.fjla.uk/owlboard/go-types v0.0.0-20230720202112-4df6f0456ea4 h1:HeHukiRnDzXN
git.fjla.uk/owlboard/go-types v0.0.0-20230720202112-4df6f0456ea4/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY=
git.fjla.uk/owlboard/go-types v0.0.0-20230720203835-cf2b2d98e86a h1:JvDUM2sIawyyLKhIOgciAj0PpVWziYlXb+RA2IgphMg=
git.fjla.uk/owlboard/go-types v0.0.0-20230720203835-cf2b2d98e86a/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY=
git.fjla.uk/owlboard/go-types v0.0.0-20230721082815-634948b5448c h1:KGxtm/m+uPo2xmZIKebUxmMQnb72hY6+GQ7ZRez/iy8=
git.fjla.uk/owlboard/go-types v0.0.0-20230721082815-634948b5448c/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY=
git.fjla.uk/owlboard/go-types v0.0.0-20230721082911-9a574276d572 h1:shnlNyIV1jG+xQsg5zCt2fEjiDzCQQeDTjTFuKZa97c=
git.fjla.uk/owlboard/go-types v0.0.0-20230721082911-9a574276d572/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

View File

@ -41,6 +41,7 @@ func formatData(dataInput *upstreamApi.Schedule) database.Service {
service := database.Service{
TransactionType: dataInput.TransactionType,
StpIndicator: dataInput.CIFSTPIndicator,
Vstp: true,
Operator: dataInput.ScheduleSegment[0].ATOCCode,
TrainUid: dataInput.CIFTrainUID,
Headcode: dataInput.ScheduleSegment[0].SignallingID,
@ -56,7 +57,11 @@ func formatData(dataInput *upstreamApi.Schedule) database.Service {
// Uses the map provided in 'helpers' to translate incorrect CIF speeds to their correct equivalent
func parseSpeed(CIFSpeed string) int32 {
log.Msg.Debug("CIFSpeed Input: " + CIFSpeed)
log.Msg.Debug("CIFSpeed Input: '" + CIFSpeed + "'")
if CIFSpeed == "" {
log.Msg.Debug("Speed data not provided")
return int32(0)
}
actualSpeed, exists := helpers.SpeedMap[CIFSpeed]
if !exists {
actualSpeed = CIFSpeed
@ -65,7 +70,7 @@ func parseSpeed(CIFSpeed string) int32 {
speed, err := strconv.ParseInt(actualSpeed, 10, 32)
if err != nil {
log.Msg.Warn("Unable to parse speed: " + CIFSpeed + ", returning nil")
log.Msg.Warn("Unable to parse speed: " + CIFSpeed + ", returning 0")
return int32(0)
}
return int32(speed)

View File

@ -19,9 +19,9 @@ func Subscribe() {
for {
msg := <-sub.C
if msg.Err != nil {
log.Msg.Error("STOMP Message Error: " + msg.Err.Error())
log.Msg.Error("\nSTOMP Message Error: " + msg.Err.Error())
} else {
log.Msg.Debug("STOMP Message Received")
log.Msg.Debug("\nSTOMP Message Received")
saveToFile(string(msg.Body), "msgBody")
handle(msg)
}