// NewDummy creates a new TCP net.Listener at a random port, a new http.ServerMux responding
// "PAYLOAD" at GET /dummy and a new http.Server with the new mux. This function also creates
// a go routine that calls server.Serve(listener).
NewDummy creates a new TCP net.Listener at a random port, a new http.ServerMux responding
"PAYLOAD" at GET /dummy and a new http.Server with the new mux. This function also creates
a go routine that calls server.Serve(listener).
// NewDummy creates a new TCP net . Listener at a random port a new http . ServerMux responding // " PAYLOAD " at GET / dummy and a new http . Server with the new mux . This function also creates // a go routine that calls server . Serve ( listener ) .
func (f *HTTPServerFactory) NewDummy() (net.Listener, *http.Server, error) {
	listener, err := net.Listen("tcp", ":0")
	if err != nil {
		return nil, nil, err
	}
	mux := http.NewServeMux()
	server := &http.Server{
		Handler: mux,
	}
	mux.HandleFunc("/dummy", func(w http.ResponseWriter, r *http.Request) {
		if r.Method != http.MethodGet {
			w.WriteHeader(http.StatusMethodNotAllowed)
			return
		}
		if _, err := w.Write([]byte("PAYLOAD")); err != nil {
			panic(fmt.Errorf("error writing dummy HTTP server response: %w", err))
		}
	})
	go f.serveAndPanicOnError(server, listener, "dummy")
	return listener, server, nil
}
func ( f * HTTPServerFactory ) NewDummy ( ) ( net . Listener , * http . Server , error ) { listener , err := net . Listen ( " " , " " ) if err != nil { return nil , nil , err } mux := http . NewServeMux ( ) server := & http . Server { Handler : mux , } mux . HandleFunc ( " " , func ( w http . ResponseWriter , r * http . Request ) { if r . Method != http . MethodGet { w . WriteHeader ( http . StatusMethodNotAllowed ) return } if _ , err := w . Write ( [ ] byte ( " " ) ) ; err != nil { panic ( fmt . Errorf ( " " , err ) ) } } ) go f . serveAndPanicOnError ( server , listener , " " ) return listener , server , nil }
NewDummy creates a new TCP net.Listener at a random port, a new http.ServerMux responding
"PAYLOAD" at GET /dummy and a new http.Server with the new mux.
NewDummy creates a new TCP net . Listener at a random port a new http . ServerMux responding " PAYLOAD " at GET / dummy and a new http . Server with the new mux .
// create listener at a random port // create server and mux