示例#1
0
文件: os.go 项目: micro/go-platform
func newOS(opts ...selector.Option) Router {
	options := selector.Options{
		Context: context.TODO(),
	}

	for _, o := range opts {
		o(&options)
	}

	c, ok := client.FromContext(options.Context)
	if !ok {
		c = client.DefaultClient
	}

	s, ok := server.FromContext(options.Context)
	if !ok {
		s = server.DefaultServer
	}

	o := &os{
		exit:   make(chan bool),
		opts:   options,
		client: c,
		server: s,
		cache:  make(map[string]*cache),
		stats:  make(map[string]*stats),
		r:      proto.NewRouterClient("go.micro.srv.router", c),
	}

	go o.run()
	return o
}
示例#2
0
文件: os.go 项目: micro/go-platform
func (o *os) Init(opts ...selector.Option) error {
	var options selector.Options
	for _, o := range opts {
		o(&options)
	}

	// TODO: Fix. This might all be really bad and hacky

	if c, ok := client.FromContext(options.Context); ok {
		o.client = c
		o.r = proto.NewRouterClient("go.micro.srv.router", c)
	}

	if s, ok := server.FromContext(options.Context); ok {
		o.server = s
	}

	return nil
}