From 67615d76dda732e374b94a2ec0b59b7fb6785bee Mon Sep 17 00:00:00 2001 From: Nedim Date: Mon, 11 Sep 2023 12:01:30 +0200 Subject: [PATCH] Added multiple services to be trigered from main API --- main.go | 22 ++++++++++++++++++++++ services/contact/contact_service.go | 11 +++++++++++ services/erp/erp_service.go | 11 +++++++++++ services/messaging/messaging_service.go | 11 +++++++++++ services/sensor/sensor_service.go | 12 ++++++++++++ 5 files changed, 67 insertions(+) create mode 100644 services/contact/contact_service.go create mode 100644 services/erp/erp_service.go create mode 100644 services/messaging/messaging_service.go create mode 100644 services/sensor/sensor_service.go diff --git a/main.go b/main.go index 84e067d..a283752 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,10 @@ import ( "gitlab.com/pactual1/backend/config" "gitlab.com/pactual1/backend/models" "gitlab.com/pactual1/backend/routes" + "gitlab.com/pactual1/backend/services/contact" + "gitlab.com/pactual1/backend/services/erp" + "gitlab.com/pactual1/backend/services/messaging" + "gitlab.com/pactual1/backend/services/sensor" "gitlab.com/pactual1/backend/shared" "github.com/gin-gonic/gin" @@ -56,6 +60,24 @@ func main() { http.ListenAndServe(":" + port, mux) }() + // Initialize channels + messagingChannel := make(chan string) + erpChannel := make(chan string) + sensorChannel := make(chan string) + contactChannel := make(chan string) + + // Start services and pass the respective channels + go messaging.MessagingService(messagingChannel) + go erp.ERPService(erpChannel) + go sensor.SensorService(sensorChannel) + go contact.ContactService(contactChannel) + + // Sending messages via channels + messagingChannel <- "Send an email" + erpChannel <- "Update ERP record" + sensorChannel <- "Trigger sensor" + contactChannel <- "Update contact info" + // Initialize Gin r := gin.Default() routes.InitRouter(r) diff --git a/services/contact/contact_service.go b/services/contact/contact_service.go new file mode 100644 index 0000000..97600ba --- /dev/null +++ b/services/contact/contact_service.go @@ -0,0 +1,11 @@ +package contact + +import ( + "fmt" +) + +func ContactService(ch chan string) { + for msg := range ch { + fmt.Println("Contact Service: ", msg) + } +} diff --git a/services/erp/erp_service.go b/services/erp/erp_service.go new file mode 100644 index 0000000..fa66f63 --- /dev/null +++ b/services/erp/erp_service.go @@ -0,0 +1,11 @@ +package erp + +import ( + "fmt" +) + +func ERPService(ch chan string) { + for msg := range ch { + fmt.Println("ERP Service: ", msg) + } +} diff --git a/services/messaging/messaging_service.go b/services/messaging/messaging_service.go new file mode 100644 index 0000000..081837d --- /dev/null +++ b/services/messaging/messaging_service.go @@ -0,0 +1,11 @@ +package messaging + +import ( + "fmt" +) + +func MessagingService(ch chan string) { + for msg := range ch { + fmt.Println("Messaging Service: ", msg) + } +} diff --git a/services/sensor/sensor_service.go b/services/sensor/sensor_service.go new file mode 100644 index 0000000..829e248 --- /dev/null +++ b/services/sensor/sensor_service.go @@ -0,0 +1,12 @@ +package sensor + +import ( + "fmt" +) + +func SensorService(ch chan string) { + for msg := range ch { + fmt.Println("Sensor Service: ", msg) + + } +} -- 2.47.3