Exemplo n.º 1
0
func ServeHTTP(t testing.TB, wg *sync.WaitGroup, app *server.App) *http.Web {
	web, err := http.New(app)
	if err != nil {
		t.Fatalf("cannot listen: %v", err)
	}
	wg.Add(1)
	go func() {
		defer wg.Done()
		// https://github.com/golang/go/issues/4373 makes it too hard to
		// filter out innocent errors, so we throw them all out.
		_ = web.Serve()
	}()
	return web
}
Exemplo n.º 2
0
func (cmd *runCommand) Run() error {
	gomaxprocs.SetToNumCPU()
	app, err := server.New(clibazil.Bazil.Config.DataDir.String())
	if err != nil {
		return err
	}
	defer app.Close()

	errCh := make(chan error)
	var wg sync.WaitGroup

	w, err := http.New(app)
	if err != nil {
		return err
	}
	wg.Add(1)
	go func() {
		defer wg.Done()
		defer w.Close()
		errCh <- w.Serve()
	}()

	c, err := control.New(app)
	if err != nil {
		return err
	}
	wg.Add(1)
	go func() {
		defer wg.Done()
		defer c.Close()
		errCh <- c.Serve()
	}()

	log.Printf("Listening on %s", w.Addr())

	wg.Wait()
	// We only care about the first error; the rest are likely to be
	// about closed listeners.
	return <-errCh
}