當前位置: 首頁>>代碼示例>>Golang>>正文


Golang client.NewClient函數代碼示例

本文整理匯總了Golang中github.com/micro/go-micro/client.NewClient函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewClient函數的具體用法?Golang NewClient怎麽用?Golang NewClient使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewClient函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

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)
}
開發者ID:micro,項目名稱:go-platform,代碼行數:27,代碼來源:labels.go

示例2: main

func main() {
	cmd.Init()

	t := trace.NewTrace()

	srv := &registry.Service{
		Name: "go.client",
	}

	client.DefaultClient = client.NewClient(
		client.Wrap(
			trace.ClientWrapper(t, srv),
		),
	)

	fmt.Println("Starting trace")
	if err := t.Start(); err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("\n--- Traced Call example ---\n")
	i := 0
	for {
		call(i)
		i++
		<-time.After(time.Second * 5)
	}

	if err := t.Stop(); err != nil {
		fmt.Println(err)
	}
}
開發者ID:jelmersnoeck,項目名稱:go-platform,代碼行數:33,代碼來源:main.go

示例3: TestBreaker

func TestBreaker(t *testing.T) {
	// setup
	r := mock.NewRegistry()
	s := selector.NewSelector(selector.Registry(r))

	c := client.NewClient(
		// set the selector
		client.Selector(s),
		// add the breaker wrapper
		client.Wrap(NewClientWrapper()),
	)

	req := c.NewJsonRequest("test.service", "Test.Method", map[string]string{
		"foo": "bar",
	})

	var rsp map[string]interface{}

	// Force to point of trip
	for i := 0; i < (hystrix.DefaultVolumeThreshold * 2); i++ {
		c.Call(context.TODO(), req, rsp)
	}

	err := c.Call(context.TODO(), req, rsp)
	if err == nil {
		t.Error("Expecting tripped breaker, got nil error")
	}

	if err.Error() != "hystrix: circuit open" {
		t.Errorf("Expecting tripped breaker, got %v", err)
	}
}
開發者ID:micro,項目名稱:go-plugins,代碼行數:32,代碼來源:hystrix_test.go

示例4: main

func main() {
	cmd.Init()

	t := zipkin.NewTrace(
		trace.Collectors("192.168.99.100:9092"),
	)
	defer t.Close()

	client.DefaultClient = client.NewClient(
		client.Wrap(
			trace.ClientWrapper(t, nil),
		),
	)

	fmt.Println("\n--- Traced Call example ---\n")
	for i := 0; i < 10; i++ {
		call(i)
	}

	/*
		fmt.Println("\n--- Streamer example ---\n")
		stream(10)

		fmt.Println("\n--- Ping Pong example ---\n")
		pingPong(10)

		fmt.Println("\n--- Publisher example ---\n")
		pub()
	*/
	<-time.After(time.Second * 10)
}
開發者ID:ZhuJingfa,項目名稱:go-platform,代碼行數:31,代碼來源:main.go

示例5: NewLabelClient

func NewLabelClient(serviceName string, c client.Client) LabelClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.router.label"
	}
	return &labelClient{
		c:           c,
		serviceName: serviceName,
	}
}
開發者ID:micro,項目名稱:router-srv,代碼行數:12,代碼來源:label.pb.go

示例6: NewGeoClient

func NewGeoClient(serviceName string, c client.Client) GeoClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "geo"
	}
	return &geoClient{
		c:           c,
		serviceName: serviceName,
	}
}
開發者ID:micro,項目名稱:micro,代碼行數:12,代碼來源:geo.pb.go

示例7: NewElasticClient

func NewElasticClient(serviceName string, c client.Client) ElasticClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.elastic"
	}
	return &elasticClient{
		c:           c,
		serviceName: serviceName,
	}
}
開發者ID:Rakanixu,項目名稱:elastic,代碼行數:12,代碼來源:elastic.pb.go

示例8: NewProfileClient

func NewProfileClient(serviceName string, c client.Client) ProfileClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "profile"
	}
	return &profileClient{
		c:           c,
		serviceName: serviceName,
	}
}
開發者ID:micro,項目名稱:micro,代碼行數:12,代碼來源:profile.pb.go

示例9: main

func main() {
	cmd.Init()

	client.DefaultClient = client.NewClient(
		client.Wrap(NewDCWrapper),
	)

	fmt.Println("\n--- Call example ---\n")
	for i := 0; i < 10; i++ {
		call(i)
	}
}
開發者ID:yonglehou,項目名稱:go-micro,代碼行數:12,代碼來源:dc_filter.go

示例10: NewMonitorClient

func NewMonitorClient(serviceName string, c client.Client) MonitorClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "monitor"
	}
	return &monitorClient{
		c:           c,
		serviceName: serviceName,
	}
}
開發者ID:huangqingcheng,項目名稱:monitoring-srv,代碼行數:12,代碼來源:monitor.pb.go

示例11: NewDBClient

func NewDBClient(serviceName string, c client.Client) DBClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.db.db"
	}
	return &dBClient{
		c:           c,
		serviceName: serviceName,
	}
}
開發者ID:micro,項目名稱:db-srv,代碼行數:12,代碼來源:db.pb.go

示例12: NewSayClient

func NewSayClient(serviceName string, c client.Client) SayClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.srv.greeter"
	}
	return &sayClient{
		c:           c,
		serviceName: serviceName,
	}
}
開發者ID:xiaoxiaoyijian,項目名稱:micro,代碼行數:12,代碼來源:hello.pb.go

示例13: NewGreeterClient

func NewGreeterClient(serviceName string, c client.Client) GreeterClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "go.micro.api.greeter"
	}
	return &greeterClient{
		c:           c,
		serviceName: serviceName,
	}
}
開發者ID:micro,項目名稱:micro,代碼行數:12,代碼來源:hello.pb.go

示例14: NewAuthClient

func NewAuthClient(serviceName string, c client.Client) AuthClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "auth"
	}
	return &authClient{
		c:           c,
		serviceName: serviceName,
	}
}
開發者ID:micro,項目名稱:micro,代碼行數:12,代碼來源:auth.pb.go

示例15: NewAccountClient

func NewAccountClient(serviceName string, c client.Client) AccountClient {
	if c == nil {
		c = client.NewClient()
	}
	if len(serviceName) == 0 {
		serviceName = "account"
	}
	return &accountClient{
		c:           c,
		serviceName: serviceName,
	}
}
開發者ID:kkszysiu,項目名稱:user-srv,代碼行數:12,代碼來源:account.pb.go


注:本文中的github.com/micro/go-micro/client.NewClient函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。