Exemplo n.º 1
0
Arquivo: run.go Projeto: jgluck/bazil
func (cmd *runCommand) Run() error {
	gomaxprocs.SetToNumCPU()
	app, err := server.New(clibazil.Bazil.Config.DataDir.String())
	if err != nil {
		return err
	}
	defer app.Close()
	c := control.New(app)
	return c.ListenAndServe()
}
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
}