// ManageServer starts srvr and wait for SIGINT or SIGQUIT or SIGKILL or SIGTERM
// to stop the server gracefully. If a second signal found or the gracePeriod
// has expired it stops the server immedietly. It returns any error that is returned
// by the srvr
ManageServer starts srvr and wait for SIGINT or SIGQUIT or SIGKILL or SIGTERM
to stop the server gracefully. If a second signal found or the gracePeriod
has expired it stops the server immedietly. It returns any error that is returned
by the srvr
// ManageServer starts srvr and wait for SIGINT or SIGQUIT or SIGKILL or SIGTERM // to stop the server gracefully . If a second signal found or the gracePeriod // has expired it stops the server immedietly . It returns any error that is returned // by the srvr
func ManageServer(srvr *http.Server, gracePeriod time.Duration) error {
	errCh := make(chan error, 0)
	sigs := []os.Signal{syscall.SIGINT, syscall.SIGQUIT, syscall.SIGKILL, syscall.SIGTERM, os.Interrupt}
	graceful := func() error {
		log.Println("Suttingdown server gracefully with in", gracePeriod)
		log.Println("To shutdown immedietly press again")
		ctx, cancel := context.WithTimeout(context.Background(), gracePeriod)
		defer cancel()
		return srvr.Shutdown(ctx)
	}
	forced := func() error {
		log.Println("Suttingdown server forcefully")
		return srvr.Close()
	}
	go func() {
		log.Println("Starting server on", srvr.Addr)
		if err := srvr.ListenAndServe(); err != http.ErrServerClosed {
			errCh <- err
		}
	}()
	go func() {
		errCh <- HandleSignals(sigs, graceful, forced)
	}()
	return <-errCh
}
func ManageServer ( srvr * http . Server , gracePeriod time . Duration ) error { errCh := make ( chan error , 0 ) sigs := [ ] os . Signal { syscall . SIGINT , syscall . SIGQUIT , syscall . SIGKILL , syscall . SIGTERM , os . Interrupt } graceful := func ( ) error { log . Println ( " " , gracePeriod ) log . Println ( " " ) ctx , cancel := context . WithTimeout ( context . Background ( ) , gracePeriod ) defer cancel ( ) return srvr . Shutdown ( ctx ) } forced := func ( ) error { log . Println ( " " ) return srvr . Close ( ) } go func ( ) { log . Println ( " " , srvr . Addr ) if err := srvr . ListenAndServe ( ) ; err != http . ErrServerClosed { errCh <- err } } ( ) go func ( ) { errCh <- HandleSignals ( sigs , graceful , forced ) } ( ) return <- errCh }
ManageServer starts srvr and wait for SIGINT or SIGQUIT or SIGKILL or SIGTERM
to stop the server gracefully.
ManageServer starts srvr and wait for SIGINT or SIGQUIT or SIGKILL or SIGTERM to stop the server gracefully .