mirror of
https://github.com/go-micro/go-micro.git
synced 2025-11-23 21:44:41 +02:00
37 lines
580 B
Markdown
37 lines
580 B
Markdown
|
|
---
|
||
|
|
layout: default
|
||
|
|
---
|
||
|
|
|
||
|
|
# RPC Client
|
||
|
|
|
||
|
|
Call a running service using the Go Micro client.
|
||
|
|
|
||
|
|
```go
|
||
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
"go-micro.dev/v5"
|
||
|
|
)
|
||
|
|
|
||
|
|
type Request struct { Name string }
|
||
|
|
|
||
|
|
type Response struct { Message string }
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
svc := micro.New("caller")
|
||
|
|
svc.Init()
|
||
|
|
|
||
|
|
req := svc.Client().NewRequest("helloworld", "Say.Hello", &Request{Name: "John"})
|
||
|
|
var rsp Response
|
||
|
|
|
||
|
|
if err := svc.Client().Call(context.TODO(), req, &rsp); err != nil {
|
||
|
|
fmt.Println("error:", err)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
fmt.Println(rsp.Message)
|
||
|
|
}
|
||
|
|
```
|