本文整理匯總了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)
}
示例2: main
func main() {
cmd.Init()
t := trace.NewTrace()
srv := ®istry.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)
}
}
示例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)
}
}
示例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)
}
示例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,
}
}
示例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,
}
}
示例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,
}
}
示例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,
}
}
示例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)
}
}
示例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,
}
}
示例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,
}
}
示例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,
}
}
示例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,
}
}
示例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,
}
}
示例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,
}
}