package messaging import ( "fmt" "github.com/jinzhu/gorm" "gitlab.com/pactual1/backend/models" ) type service struct { ch chan models.Notification db *gorm.DB } var MessagingChannel chan models.Notification func NewService(ch chan models.Notification, db *gorm.DB) service { MessagingChannel = ch return service{ ch: MessagingChannel, db: db, } } func (s service) MessagingService() { for notification := range s.ch { fmt.Println("Messaging Service received: ", notification) // Save the notification to the database if err := s.db.Create(¬ification).Error; err != nil { fmt.Printf("Error saving notification to DB: %v\n", err) } } } func GetMessagingChannel() chan models.Notification { return MessagingChannel }