1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-11-23 21:44:41 +02:00
Files
go-micro/internal/website/docs/examples/rpc-client.md
2025-11-13 18:11:29 +00:00

580 B

layout
layout
default

RPC Client

Call a running service using the Go Micro client.

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)
}