func (proxy *Proxy) serveWithDoppler(writer http.ResponseWriter, request *http.Request, dopplerEndpoint doppler_endpoint.DopplerEndpoint) { messagesChan := make(chan []byte, 100) stopChan := make(chan struct{}) defer close(stopChan) go proxy.connector.Connect(dopplerEndpoint, messagesChan, stopChan) handler := dopplerEndpoint.HProvider(messagesChan, proxy.logger) handler.ServeHTTP(writer, request) }
func (c *ChannelGroupConnector) connectToServer(serverAddress string, dopplerEndpoint doppler_endpoint.DopplerEndpoint, messagesChan chan<- []byte, stopChan <-chan struct{}) { l := c.listenerConstructor(dopplerEndpoint.Timeout, c.batcher, c.logger) serverUrl := fmt.Sprintf("ws://%s%s", serverAddress, dopplerEndpoint.GetPath()) c.logger.Infof("proxy: connecting to doppler at %s", serverUrl) appId := dopplerEndpoint.StreamId err := l.Start(serverUrl, appId, messagesChan, stopChan) if err != nil { errorMsg := fmt.Sprintf("proxy: error connecting to %s: %s", serverAddress, err.Error()) messagesChan <- c.generateLogMessage(errorMsg, appId) c.logger.Errorf("proxy: error connecting %s %s %s", appId, dopplerEndpoint.Endpoint, err.Error()) } }