mirror of
https://github.com/go-micro/go-micro.git
synced 2025-11-23 21:44:41 +02:00
new copilot generated documentation
This commit is contained in:
36
internal/website/docs/examples/rpc-client.md
Normal file
36
internal/website/docs/examples/rpc-client.md
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
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)
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user