pomerium/internal/tests/xdserr/echo.go
Caleb Doxsey bbed421cd8
config: remove source, remove deadcode, fix linting issues (#4118)
* remove source, remove deadcode, fix linting issues

* use github action for lint

* fix missing envoy
2023-04-21 17:25:11 -06:00

34 lines
620 B
Go

package xdserr
import (
"context"
"fmt"
"net"
"net/http"
"golang.org/x/sync/errgroup"
)
func echo(w http.ResponseWriter, _ *http.Request) {
fmt.Fprintf(w, "pong")
}
// RunEcho runs a test echo http server
func RunEcho(ctx context.Context) (string, error) {
l, err := net.Listen("tcp", "localhost:0")
if err != nil {
return "", err
}
mux := http.NewServeMux()
mux.HandleFunc("/", echo)
srv := http.Server{
Handler: mux,
}
eg, ctx := errgroup.WithContext(ctx)
eg.Go(func() error { return srv.Serve(l) })
eg.Go(func() error {
<-ctx.Done()
return srv.Close()
})
return l.Addr().String(), nil
}