示例#1
0
文件: server.go 项目: pombredanne/bar
func NewFixtureServer(name string) (res *FixtureServer, err error) {
	logx.SetLevel(logx.DEBUG)

	wd, _ := os.Getwd()
	rt := filepath.Join(wd, "testdata", name+"-srv")
	os.RemoveAll(rt)

	p := storage.NewBlockStorage(&storage.BlockStorageOptions{rt, 2, 32, 64})
	ports, err := GetOpenPorts(2)
	if err != nil {
		return
	}

	ctx := context.Background()
	info := &proto.ServerInfo{
		HTTPEndpoint: fmt.Sprintf("http://localhost:%d/v1", ports[0]),
		RPCEndpoints: []string{fmt.Sprintf("localhost:%d", ports[1])},
		ChunkSize:    1024 * 1024 * 2,
		PoolSize:     16,
		BufferSize:   1024 * 1024 * 8,
	}

	tServer := thrift.NewServer(ctx,
		&thrift.Options{info, fmt.Sprintf(":%d", ports[1])}, p)
	hServer := front.NewServer(ctx,
		&front.Options{info, fmt.Sprintf(":%d", ports[0]), ""}, p)

	res = &FixtureServer{
		server.NewCompositeServer(ctx, tServer, hServer),
		info,
		rt,
	}
	go res.Start()
	time.Sleep(time.Millisecond * 00)
	return
}
示例#2
0
func (c *ServerRunCmd) Run(args ...string) (err error) {
	stor, err := storage.GuessStorage(c.Storage)
	if err != nil {
		return
	}

	info := &proto.ServerInfo{
		HTTPEndpoint: c.ServerOptions.HTTPEndpoint,
		RPCEndpoints: strings.Split(c.Endpoint, ","),
		ChunkSize:    c.ChunkSize,
		PoolSize:     c.PoolSize,
		BufferSize:   c.BufferSize,
	}
	ctx := context.Background()
	// Thrift
	tServer := thrift.NewServer(ctx, &thrift.Options{info, c.BindRPC}, stor)
	httpServer := front.NewServer(ctx, &front.Options{info, c.BindHTTP, c.BinDir}, stor)

	srv := server.NewCompositeServer(ctx, tServer, httpServer)

	err = srv.Start()

	return
}