mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-06 08:16:03 +02:00
35 lines
575 B
Go
35 lines
575 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
hello "github.com/asim/go-micro/examples/v4/greeter/srv/proto/hello"
|
|
"go-micro.dev/v4"
|
|
"go-micro.dev/v4/metadata"
|
|
|
|
"context"
|
|
)
|
|
|
|
func main() {
|
|
service := micro.NewService()
|
|
service.Init()
|
|
|
|
cl := hello.NewSayService("go.micro.srv.greeter", service.Client())
|
|
|
|
// Set arbitrary headers in context
|
|
ctx := metadata.NewContext(context.Background(), map[string]string{
|
|
"User": "john",
|
|
"ID": "1",
|
|
})
|
|
|
|
rsp, err := cl.Hello(ctx, &hello.Request{
|
|
Name: "John",
|
|
})
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
fmt.Println(rsp.Msg)
|
|
}
|