micro/examples/service_client.go
2015-05-21 19:24:57 +01:00

33 lines
687 B
Go

package main
import (
"fmt"
"github.com/myodc/go-micro/client"
"github.com/myodc/go-micro/cmd"
example "github.com/myodc/go-micro/template/proto/example"
)
func main() {
cmd.Init()
client.DefaultClient = client.NewRpcClient()
// Create new request to service go.micro.service.go-template, method Example.Call
req := client.NewRequest("go.micro.service.template", "Example.Call", &example.Request{
Name: "John",
})
// Set arbitrary headers
req.Headers().Set("X-User-Id", "john")
req.Headers().Set("X-From-Id", "script")
rsp := &example.Response{}
// Call service
if err := client.Call(req, rsp); err != nil {
fmt.Println(err)
return
}
fmt.Println(rsp.Msg)
}