Added multiple services to be trigered from main API
This commit is contained in:
22
main.go
22
main.go
@@ -8,6 +8,10 @@ import (
|
|||||||
"gitlab.com/pactual1/backend/config"
|
"gitlab.com/pactual1/backend/config"
|
||||||
"gitlab.com/pactual1/backend/models"
|
"gitlab.com/pactual1/backend/models"
|
||||||
"gitlab.com/pactual1/backend/routes"
|
"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"
|
"gitlab.com/pactual1/backend/shared"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -56,6 +60,24 @@ func main() {
|
|||||||
http.ListenAndServe(":" + port, mux)
|
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
|
// Initialize Gin
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
routes.InitRouter(r)
|
routes.InitRouter(r)
|
||||||
|
|||||||
11
services/contact/contact_service.go
Normal file
11
services/contact/contact_service.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package contact
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ContactService(ch chan string) {
|
||||||
|
for msg := range ch {
|
||||||
|
fmt.Println("Contact Service: ", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
11
services/erp/erp_service.go
Normal file
11
services/erp/erp_service.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package erp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ERPService(ch chan string) {
|
||||||
|
for msg := range ch {
|
||||||
|
fmt.Println("ERP Service: ", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
11
services/messaging/messaging_service.go
Normal file
11
services/messaging/messaging_service.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package messaging
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MessagingService(ch chan string) {
|
||||||
|
for msg := range ch {
|
||||||
|
fmt.Println("Messaging Service: ", msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
12
services/sensor/sensor_service.go
Normal file
12
services/sensor/sensor_service.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package sensor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SensorService(ch chan string) {
|
||||||
|
for msg := range ch {
|
||||||
|
fmt.Println("Sensor Service: ", msg)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user