- gitHandler := &cgi.Handler{
- Path: theConfig.GitCommand,
- Dir: theConfig.Root,
- Env: []string{
- "GIT_PROJECT_ROOT=" + theConfig.Root,
- "GIT_HTTP_EXPORT_ALL=",
- },
- InheritEnv: []string{"PATH"},
- Args: []string{"http-backend"},
- }
-
- // The rest of the work here is essentially
- // http.ListenAndServe() with two more features: (1) whoever
- // called Start() can discover which address:port we end up
- // listening to -- which makes listening on ":0" useful in
- // test suites -- and (2) the server can be shut down without
- // killing the process -- which is useful in test cases, and
- // makes it possible to shut down gracefully on SIGTERM
- // without killing active connections.
-
- addr, err := net.ResolveTCPAddr("tcp", theConfig.Addr)
- if err != nil {
- return err
- }
- srv.listener, err = net.ListenTCP("tcp", addr)
- if err != nil {
- return err
- }
- srv.Addr = srv.listener.Addr().String()