Exemplo n.º 1
0
func start() {
	workers := runtime.GOMAXPROCS(0)

	idl := barrister.MustParseIdlJson([]byte(calc.IdlJsonRaw))
	svr := calc.NewJSONServer(idl, true, CalculatorImpl{})

	stop := make(chan bool)
	wg := new(sync.WaitGroup)

	for i := 0; i < workers; i++ {
		go runWorker(svr, wg, stop)
		wg.Add(1)
	}

	log.Printf("Started %d worker(s)\n", workers)

	quit := make(chan os.Signal, 1)
	signal.Notify(quit, os.Interrupt)
	<-quit

	log.Println("Stopping workers")
	for i := 0; i < workers; i++ {
		stop <- true
	}
	wg.Wait()
	log.Println("Exiting")
}
Exemplo n.º 2
0
func main() {
	idl := barrister.MustParseIdlJson([]byte(calc.IdlJsonRaw))
	svr := calc.NewJSONServer(idl, true, CalculatorImpl{})
	svr.AddFilter(LogFilter{})
	http.Handle("/", &svr)

	fmt.Println("Starting Calculator server on localhost:9233")
	err := http.ListenAndServe(":9233", nil)
	if err != nil {
		panic(err)
	}
}