示例#1
0
func main() {
	c, err := core.NewConfig()
	if err != nil {
		log.Fatal(err)
	}

	ctx, err := core.NewContext(c)
	if err != nil {
		log.Fatal(err)
	}
	defer ctx.Close()

	ffs := gateway.FeedFactories(c)
	gatewayController, err := gateway.NewGatewayController(ffs, ctx.DB, ctx.N, ctx.DL, c.IbGws, c.IbClientId)
	if err != nil {
		log.Fatal(err)
	}
	defer gatewayController.Close()

	terminated := handleSignals()

	handler := server.Handler(c.ErrInfo, ctx.DB, ctx.N)
	err = server.Serve(terminated, c.Address(), handler)
	if err != nil {
		log.Fatal(err)
	}

	// ensure we have terminated (useful if HTTP server commented out etc)
	<-terminated
}
示例#2
0
func TestServeExitsOnChannelClose(t *testing.T) {
	ctx, handler := NewTestHandler(t)
	defer ctx.Close()

	c, err := core.NewConfig()
	if err != nil {
		t.Fatal(err)
	}

	terminated := make(chan struct{})

	go func() {
		time.Sleep(100 * time.Millisecond)
		close(terminated)
	}()

	err = Serve(terminated, c.Address(), handler)
	if err != nil {
		t.Fatal(err)
	}
}