Ejemplo n.º 1
0
// listen starts one or more listeners for the handler. The list
// of addresses are
func listen(addrs string, wait time.Duration, h http.Handler) {
	for _, addr := range commas.Split(addrs, -1) {
		if addr == "" {
			continue
		}

		p := semicolons.Split(addr, 4)
		switch len(p) {
		case 1:
			go listenAndServe(p[0], h)
		case 2:
			go listenAndServeTLS(p[0], p[1], p[1], h)
		case 3:
			go listenAndServeTLS(p[0], p[1], p[2], h)
		default:
			log.Fatal("[FATAL] Invalid address format ", addr)
		}
	}

	// wait for shutdown signal
	<-quit

	// disable routing for all requests
	route.Shutdown()

	// trigger graceful shutdown
	log.Printf("[INFO] Graceful shutdown over %s", wait)
	time.Sleep(wait)
	log.Print("[INFO] Down")
}
Ejemplo n.º 2
0
// startListeners runs one or more listeners for the handler
func startListeners(listen []config.Listen, wait time.Duration, h http.Handler) {
	for _, l := range listen {
		go listenAndServe(l, h)
	}

	// wait for shutdown signal
	<-quit

	// disable routing for all requests
	route.Shutdown()

	// trigger graceful shutdown
	log.Printf("[INFO] Graceful shutdown over %s", wait)
	time.Sleep(wait)
	log.Print("[INFO] Down")
}