packagehttputilimport("context""fmt""net/http""time")funcListenAndServeContext(ctxcontext.Context,server*http.Server)error{errCh:=make(chanerror)gofunc(){errCh<-server.ListenAndServe()}()// verify that the server comes uptick:=time.NewTimer(10*time.Millisecond)select{caseerr:=<-errCh:returnfmt.Errorf("http server failed: %w",err)case<-tick.C:break}<-ctx.Done()returnctx.Err()}