From b0cbab3e34904de82643a96c2e3ee922a412b3fa Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 25 Mar 2024 11:26:07 +0000 Subject: [PATCH] Change module name: - Update go target version - Change imports to reflect new module name - Update repo URL for new module name --- src/dbAccess/access.go | 4 ++-- src/dbAccess/client.go | 2 +- src/go.mod | 4 ++-- src/go.sum | 9 +++++---- src/log/log.go | 2 +- src/main.go | 33 +++++++++++++++++++-------------- src/messaging/client.go | 34 ++++++++-------------------------- src/vstp/actions.go | 4 ++-- src/vstp/handler.go | 2 +- src/vstp/parser.go | 4 ++-- src/vstp/subscribe.go | 4 ++-- 11 files changed, 45 insertions(+), 57 deletions(-) diff --git a/src/dbAccess/access.go b/src/dbAccess/access.go index 0f792b3..3dbeab0 100644 --- a/src/dbAccess/access.go +++ b/src/dbAccess/access.go @@ -4,8 +4,8 @@ import ( "context" "git.fjla.uk/owlboard/go-types/pkg/database" - "git.fjla.uk/owlboard/mq-client/helpers" - "git.fjla.uk/owlboard/mq-client/log" + "git.fjla.uk/owlboard/timetable-mgr/helpers" + "git.fjla.uk/owlboard/timetable-mgr/log" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo/options" ) diff --git a/src/dbAccess/client.go b/src/dbAccess/client.go index 4ec8438..bcf1edb 100644 --- a/src/dbAccess/client.go +++ b/src/dbAccess/client.go @@ -1,7 +1,7 @@ package dbAccess import ( - "git.fjla.uk/owlboard/mq-client/log" + "git.fjla.uk/owlboard/timetable-mgr/log" "context" "fmt" diff --git a/src/go.mod b/src/go.mod index a241005..2b95b76 100644 --- a/src/go.mod +++ b/src/go.mod @@ -1,6 +1,6 @@ -module git.fjla.uk/owlboard/mq-client +module git.fjla.uk/owlboard/timetable-mgr -go 1.19 +go 1.21 require ( git.fjla.uk/owlboard/go-types v0.0.0-20230727192011-171bd3eafd83 diff --git a/src/go.sum b/src/go.sum index 41565c3..1a6e4f9 100644 --- a/src/go.sum +++ b/src/go.sum @@ -1,10 +1,7 @@ -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= -git.fjla.uk/owlboard/go-types v0.0.0-20230727191457-d15ddc556312 h1:IolAJJTttdcmykOI73Zjfh3V8Gd01l9TrM+OmliM4h0= -git.fjla.uk/owlboard/go-types v0.0.0-20230727191457-d15ddc556312/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY= git.fjla.uk/owlboard/go-types v0.0.0-20230727192011-171bd3eafd83 h1:q+I66M4YVRnKwdyYqcwou7TTniM1uwUSh3Bpa8SDLuM= git.fjla.uk/owlboard/go-types v0.0.0-20230727192011-171bd3eafd83/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= 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= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -26,11 +23,13 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= @@ -46,6 +45,7 @@ go.mongodb.org/mongo-driver v1.12.0/go.mod h1:AZkxhPnFJUoH7kZlFkVKucV20K387miPfm go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= +go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= @@ -97,3 +97,4 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/src/log/log.go b/src/log/log.go index d120a1e..cf78950 100644 --- a/src/log/log.go +++ b/src/log/log.go @@ -4,7 +4,7 @@ import ( "go.uber.org/zap" "go.uber.org/zap/zapcore" - "git.fjla.uk/owlboard/mq-client/helpers" + "git.fjla.uk/owlboard/timetable-mgr/helpers" ) var Msg *zap.Logger diff --git a/src/main.go b/src/main.go index 46d48bc..fff9197 100644 --- a/src/main.go +++ b/src/main.go @@ -6,11 +6,11 @@ import ( "os/signal" "syscall" - "git.fjla.uk/owlboard/mq-client/dbAccess" - "git.fjla.uk/owlboard/mq-client/helpers" - "git.fjla.uk/owlboard/mq-client/log" - "git.fjla.uk/owlboard/mq-client/messaging" - "git.fjla.uk/owlboard/mq-client/vstp" + "git.fjla.uk/owlboard/timetable-mgr/dbAccess" + "git.fjla.uk/owlboard/timetable-mgr/helpers" + "git.fjla.uk/owlboard/timetable-mgr/log" + "git.fjla.uk/owlboard/timetable-mgr/messaging" + "git.fjla.uk/owlboard/timetable-mgr/vstp" ) func main() { @@ -24,30 +24,35 @@ func main() { log.Msg.Info("Initialised OwlBoard timetable-mgr " + helpers.Version) - defer cleanup() + defer cleanup(cfg) - go handleSignals() + if cfg.VstpOn { + messaging.StompInit(cfg) + go handleSignals(cfg) - vstp.Subscribe() + vstp.Subscribe() + } } // Traps SIGINT and SIGTERM signals and ensures cleanup() is run -func handleSignals() { +func handleSignals(cfg *helpers.Configuration) { sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) sig := <-sigChan log.Msg.Warn("Signal received: " + sig.String()) - cleanup() + cleanup(cfg) os.Exit(1) } // Cleans up open connections ready for a clean exit of the program -func cleanup() { +func cleanup(cfg *helpers.Configuration) { log.Msg.Debug("Cleaning up open connections") - if messaging.Client != nil { - log.Msg.Info("Closing STOMP Client") - messaging.Disconnect(messaging.Client) + if cfg.VstpOn { + if messaging.Client != nil { + log.Msg.Info("Closing STOMP Client") + messaging.Disconnect(messaging.Client) + } } if dbAccess.MongoClient != nil { log.Msg.Info("Closing MongoDB Client") diff --git a/src/messaging/client.go b/src/messaging/client.go index 40ce487..f6b6d09 100644 --- a/src/messaging/client.go +++ b/src/messaging/client.go @@ -1,41 +1,23 @@ package messaging import ( - "os" - - "git.fjla.uk/owlboard/mq-client/log" - + "git.fjla.uk/owlboard/timetable-mgr/helpers" + "git.fjla.uk/owlboard/timetable-mgr/log" "github.com/go-stomp/stomp/v3" ) -type nrodCredential struct { - user string - pass string -} +var Client *stomp.Conn -// Fetches credentials from environment variables and exits if none provided. -func getCredentials() nrodCredential { - var nrod_user string = os.Getenv("OWL_LDB_CORPUSUSER") - var nrod_pass string = os.Getenv("OWL_LDB_CORPUSPASS") - if nrod_user == "" || nrod_pass == "" { - log.Msg.Fatal("No NROD Credentials provided") - } - log.Msg.Debug("NROD Credentials loaded for user: " + nrod_user) - return nrodCredential{ - user: nrod_user, - pass: nrod_pass, - } +func StompInit(cfg *helpers.Configuration) { + Client = dial(cfg.NrodUser, cfg.NrodPass) } -var Client = dial() - // Connects the STOMP file to the Network Rail MQ Server -func dial() *stomp.Conn { - var credentials nrodCredential = getCredentials() +func dial(user, pass string) *stomp.Conn { conn, err := stomp.Dial("tcp", "publicdatafeeds.networkrail.co.uk:61618", - stomp.ConnOpt.Login(credentials.user, credentials.pass), + stomp.ConnOpt.Login(user, pass), stomp.ConnOpt.HeartBeat(15000, 15000), - stomp.ConnOpt.Header("client-id", credentials.user+"-mq-client"), + stomp.ConnOpt.Header("client-id", user+"-mq-client"), ) if err != nil { log.Msg.Fatal("Unable to connect to STOMP Client: " + err.Error()) diff --git a/src/vstp/actions.go b/src/vstp/actions.go index 84d727d..5111088 100644 --- a/src/vstp/actions.go +++ b/src/vstp/actions.go @@ -4,8 +4,8 @@ import ( "fmt" "git.fjla.uk/owlboard/go-types/pkg/database" - "git.fjla.uk/owlboard/mq-client/dbAccess" - "git.fjla.uk/owlboard/mq-client/log" + "git.fjla.uk/owlboard/timetable-mgr/dbAccess" + "git.fjla.uk/owlboard/timetable-mgr/log" ) // Decide, based on the DB Formatted message type, what action needs taking diff --git a/src/vstp/handler.go b/src/vstp/handler.go index 6ac9539..9cc2d71 100644 --- a/src/vstp/handler.go +++ b/src/vstp/handler.go @@ -3,7 +3,7 @@ package vstp import ( "fmt" - "git.fjla.uk/owlboard/mq-client/log" + "git.fjla.uk/owlboard/timetable-mgr/log" "github.com/go-stomp/stomp/v3" ) diff --git a/src/vstp/parser.go b/src/vstp/parser.go index 81ce73c..e0cf7ee 100644 --- a/src/vstp/parser.go +++ b/src/vstp/parser.go @@ -9,8 +9,8 @@ import ( "git.fjla.uk/owlboard/go-types/pkg/database" "git.fjla.uk/owlboard/go-types/pkg/upstreamApi" - "git.fjla.uk/owlboard/mq-client/helpers" - "git.fjla.uk/owlboard/mq-client/log" + "git.fjla.uk/owlboard/timetable-mgr/helpers" + "git.fjla.uk/owlboard/timetable-mgr/log" ) // Unmarshals the JSON data and runs it through the formatData() function and returns the data in a DB ready Struct diff --git a/src/vstp/subscribe.go b/src/vstp/subscribe.go index f0de1a4..438d65c 100644 --- a/src/vstp/subscribe.go +++ b/src/vstp/subscribe.go @@ -3,8 +3,8 @@ package vstp import ( "time" - "git.fjla.uk/owlboard/mq-client/log" - "git.fjla.uk/owlboard/mq-client/messaging" + "git.fjla.uk/owlboard/timetable-mgr/log" + "git.fjla.uk/owlboard/timetable-mgr/messaging" "github.com/go-stomp/stomp/v3" )