Exemplo n.º 1
0
func main() {
	cmd.Init()

	r := router.NewRouter()
	c := client.NewClient(client.Selector(r))
	c = router.NewLabelWrapper(c)

	// Create new request to service go.micro.srv.greeter, method Say.Hello
	req := c.NewRequest("go.micro.srv.greeter", "Say.Hello", &hello.Request{
		Name: "John",
	})

	rsp := &hello.Response{}

	// Set arbitrary headers in context
	ctx := metadata.NewContext(context.Background(), map[string]string{
		router.LabelPrefix + "Greeter": "one",
	})

	// Call service
	if err := c.Call(ctx, req, rsp); err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(rsp.Msg)
}
Exemplo n.º 2
0
func main() {
	cmd.Init()

	r := router.NewRouter()
	defer r.Close()

	ch := make(chan map[string]int, routines)
	stats := make(map[string]int)

	for i := 0; i < routines; i++ {
		go func(j int) {
			st := selector(j, r)
			str := ""
			for k, v := range st {
				str += fmt.Sprintf("stats %d %s %d\n", j, k, v)
			}
			fmt.Println(str)
			ch <- st
		}(i)
	}

	// collate stats
	for i := 0; i < routines; i++ {
		st := <-ch
		for k, v := range st {
			stats[k] += v
		}
	}

	for k, v := range stats {
		fmt.Println("overall stats", k, v)
	}
}
Exemplo n.º 3
0
func NewRouter(opts ...selector.Option) router.Router {
	return router.NewRouter(opts...)
}