func main() {
	//go RunTestServer(":8088")
	//go RunTestServer(":8089")
	//go RunTestServer(":8090")

	config := ParseArgs()

	logger, err := CreateLogger(config.LogLevel, "leska")
	utils.HandleErrorWithoutLogger("cannot create logger", err)
	logger.Debugf("start leska with config: %v", config)

	// TODO: прокинуть Repeate-настроки куда нужно
	forwarder, err := CreateForwarder(logger, config.Upstreams)
	utils.HandleError(logger, "cannot create forwarder", err)

	storer, err := storage.StartStorer(logger, config.Storage, config.RepeatNumber,
		5*time.Second, 100000)
	utils.HandleError(logger, "cannot create storer", err)
	defer storer.Stop()

	repeater, err := StartRepeater(logger, forwarder, storer,
		config.RepeatTimeout, config.RepeatNumber)
	utils.HandleError(logger, "cannot create repeater", err)
	defer repeater.Stop()

	err = httpdown.ListenAndServe(
		&http.Server{
			Addr:    config.Address,
			Handler: NewStreamer(logger, storer, forwarder),
		},
		&httpdown.HTTP{
			StopTimeout: 10 * time.Second,
			KillTimeout: 1 * time.Second,
		})
	utils.HandleError(logger, "cannot start server", err)
}
func main() {
	//go RunTestServer(":8088")
	//go RunTestServer(":8089")
	//go RunTestServer(":8090")

	config := ParseArgs()

	logger, err := CreateLogger(config.LogLevel, "leska")
	utils.HandleErrorWithoutLogger("cannot create logger", err)
	logger.Debugf("start leska with config: %v", config)

	// TODO: прокинуть Repeate-настроки куда нужно
	forwarder, err := CreateForwarder(logger, config.Upstreams)
	utils.HandleError(logger, "cannot create forwarder", err)

	storer, err := storage.StartStorer(logger, config.Storage, config.RepeatNumber,
		5*time.Second, 100000)
	utils.HandleError(logger, "cannot create storer", err)
	defer storer.Stop()

	repeater, err := StartRepeater(logger, forwarder, storer,
		config.RepeatTimeout, config.RepeatNumber)
	utils.HandleError(logger, "cannot create repeater", err)
	defer repeater.Stop()

	err = httpdown.ListenAndServe(
		&http.Server{
			Addr:    config.Address,
			Handler: NewStreamer(logger, storer, forwarder),
		},
		&httpdown.HTTP{
			StopTimeout: 10 * time.Second,
			KillTimeout: 1 * time.Second,
		})
	utils.HandleError(logger, "cannot start server", err)
}
/////////////////////////////////////////////////
// TODO: возможно в эту задачу хорошо подойдет fasthttp. Нужно будет посмотреть
// TODO: на сколько все станет сложнее.