MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cloud-sql-proxy / startHTTPServer

Function startHTTPServer

cmd/root.go:1278–1301  ·  view source on GitHub ↗
(ctx context.Context, l cloudsql.Logger, addr string, mux *http.ServeMux, shutdownCh chan<- error)

Source from the content-addressed store, hash-verified

1276}
1277
1278func startHTTPServer(ctx context.Context, l cloudsql.Logger, addr string, mux *http.ServeMux, shutdownCh chan<- error) {
1279 server := &http.Server{
1280 Addr: addr,
1281 Handler: mux,
1282 }
1283 // Start the HTTP server.
1284 go func() {
1285 err := server.ListenAndServe()
1286 if errors.Is(err, http.ErrServerClosed) {
1287 return
1288 }
1289 if err != nil {
1290 shutdownCh <- fmt.Errorf("failed to start HTTP server: %v", err)
1291 }
1292 }()
1293 // Handle shutdown of the HTTP server gracefully.
1294 <-ctx.Done()
1295 // Give the HTTP server a second to shut down cleanly.
1296 ctx2, cancel := context.WithTimeout(context.Background(), time.Second)
1297 defer cancel()
1298 if err := server.Shutdown(ctx2); err != nil {
1299 l.Errorf("failed to shutdown HTTP server: %v\n", err)
1300 }
1301}

Callers 1

runSignalWrapperFunction · 0.85

Calls 2

DoneMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected