1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-11 17:18:28 +02:00
go-micro/examples/metadata/cli/main.go
2020-12-26 15:17:20 +00:00

35 lines
590 B
Go

package main
import (
"fmt"
hello "github.com/micro/examples/greeter/srv/proto/hello"
"github.com/micro/go-micro/v2"
"github.com/micro/go-micro/v2/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)
}