func (s *Server) Start(ctx context.Context, dataChan chan<- *metrics.EventMetrics) error {
	s.dataChan = dataChan

	// 100 outstanding stats update requests
	statsChan := make(chan string, 100)

	laddr := s.ln.Addr().String()
	go s.statsKeeper(fmt.Sprintf("http-server-%s", laddr), statsChan)

	// Not using default server mux as we may run multiple HTTP servers, e.g. for testing.
	serverMux := http.NewServeMux()
	serverMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		s.handler(w, r, statsChan)
	})
	s.l.Infof("Starting HTTP server at: %s", laddr)
	srv := &http.Server{
		Addr:         laddr,
		Handler:      serverMux,
		ReadTimeout:  time.Duration(s.c.GetReadTimeoutMs()) * time.Millisecond,
		WriteTimeout: time.Duration(s.c.GetWriteTimeoutMs()) * time.Millisecond,
		IdleTimeout:  time.Duration(s.c.GetIdleTimeoutMs()) * time.Millisecond,
	}

	// Setup a background function to close server if context is canceled.
	go func() {
		<-ctx.Done()
		srv.Close()
	}()

	// Following returns only in case of an error.
	return srv.Serve(s.ln)
}
// Start starts a simple HTTP server on a given port. This function returns
// only if there is an error.
Start starts a simple HTTP server on a given port. This function returns
only if there is an error.
// Start starts a simple HTTP server on a given port . This function returns // only if there is an error .
func (s *Server) Start(ctx context.Context, dataChan chan<- *metrics.EventMetrics) error {
	s.dataChan = dataChan
	statsChan := make(chan string, 100)
	laddr := s.ln.Addr().String()
	go s.statsKeeper(fmt.Sprintf("http-server-%s", laddr), statsChan)
	serverMux := http.NewServeMux()
	serverMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		s.handler(w, r, statsChan)
	})
	s.l.Infof("Starting HTTP server at: %s", laddr)
	srv := &http.Server{
		Addr:         laddr,
		Handler:      serverMux,
		ReadTimeout:  time.Duration(s.c.GetReadTimeoutMs()) * time.Millisecond,
		WriteTimeout: time.Duration(s.c.GetWriteTimeoutMs()) * time.Millisecond,
		IdleTimeout:  time.Duration(s.c.GetIdleTimeoutMs()) * time.Millisecond,
	}
	go func() {
		<-ctx.Done()
		srv.Close()
	}()
	return srv.Serve(s.ln)
}
func ( s * Server ) Start ( ctx context . Context , dataChan chan <- * metrics . EventMetrics ) error { s . dataChan = dataChan statsChan := make ( chan string , 100 ) laddr := s . ln . Addr ( ) . String ( ) go s . statsKeeper ( fmt . Sprintf ( " " , laddr ) , statsChan ) serverMux := http . NewServeMux ( ) serverMux . HandleFunc ( " " , func ( w http . ResponseWriter , r * http . Request ) { s . handler ( w , r , statsChan ) } ) s . l . Infof ( " " , laddr ) srv := & http . Server { Addr : laddr , Handler : serverMux , ReadTimeout : time . Duration ( s . c . GetReadTimeoutMs ( ) ) * time . Millisecond , WriteTimeout : time . Duration ( s . c . GetWriteTimeoutMs ( ) ) * time . Millisecond , IdleTimeout : time . Duration ( s . c . GetIdleTimeoutMs ( ) ) * time . Millisecond , } go func ( ) { <- ctx . Done ( ) srv . Close ( ) } ( ) return srv . Serve ( s . ln ) }
Start starts a simple HTTP server on a given port.
Start starts a simple HTTP server on a given port .
// 100 outstanding stats update requests // Not using default server mux as we may run multiple HTTP servers, e.g. for testing. // Setup a background function to close server if context is canceled. // Following returns only in case of an error.