Exemple #1
0
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
}
Exemple #2
0
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
}