func()

in pkg/proxy/proxy.go [92:118]


func (p *proxy) Run(ctx context.Context) error {
	rtr := mux.NewRouter()
	rtr.PathPrefix(tokenPathPrefix).HandlerFunc(p.msiHandler)
	rtr.PathPrefix(readyzPathPrefix).HandlerFunc(p.readyzHandler)
	rtr.PathPrefix("/").HandlerFunc(p.defaultPathHandler)

	p.logger.Info("starting the proxy server", "port", p.port, "userAgent", userAgent)
	server := &http.Server{
		Addr:              fmt.Sprintf("%s:%d", localhost, p.port),
		ReadHeaderTimeout: 5 * time.Second,
		Handler:           rtr,
	}

	go func() {
		if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
			panic(err)
		}
	}()

	<-ctx.Done()

	p.logger.Info("shutting down the proxy server")
	// shutdown the server gracefully with a 5 second timeout
	shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	return server.Shutdown(shutdownCtx)
}