package notification import ( "fmt" "github.com/jinzhu/gorm" "gitlab.com/pactual1/backend/models" ) type service struct { ch chan models.Notification db *gorm.DB } func NewService(ch chan models.Notification, db *gorm.DB) service { return service{ ch: ch, 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) } } }