bambou/pushcenter.go
func (p *PushCenter) Start() error {

	if p.isRunning {
		return errors.New("the push center is already started")
	}

	p.isRunning = true

	go func() {
		lastEventID := ""
		for {
			go p.session.NextEvent(p.Channel, lastEventID)
			select {
			case notification := <-p.Channel:
				for _, event := range notification.Events {

					buffer := &bytes.Buffer{}
					if err := json.NewEncoder(buffer).Encode(event.DataMap[0]); err != nil {
						continue
					}
					event.Data = buffer.Bytes()

					lastEventID = notification.UUID
					if p.defaultHander != nil {
						p.defaultHander(event)
					}

					if handler, exists := p.handlers[event.EntityType]; exists {
						handler(event)
					}
				}
			case <-p.stop:
				return
			}
		}
	}()

	return nil
}
func (p *PushCenter) Start() error {

	if p.isRunning {
		return errors.New("the push center is already started")
	}

	p.isRunning = true

	go func() {
		lastEventID := ""
		for {
			go p.session.NextEvent(p.Channel, lastEventID)
			select {
			case notification := <-p.Channel:
				for _, event := range notification.Events {

					buffer := &bytes.Buffer{}
					if err := json.NewEncoder(buffer).Encode(event.DataMap[0]); err != nil {
						continue
					}
					event.Data = buffer.Bytes()

					lastEventID = notification.UUID
					if p.defaultHander != nil {
						p.defaultHander(event)
					}

					if handler, exists := p.handlers[event.EntityType]; exists {
						handler(event)
					}
				}
			case <-p.stop:
				return
			}
		}
	}()

	return nil
}
// Start starts the Push Center.