1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-12 22:07:47 +02:00
go-micro/examples/service_client.go

30 lines
596 B
Go
Raw Normal View History

2015-01-13 23:31:27 +00:00
package main
import (
"fmt"
2015-05-05 19:05:06 +01:00
"github.com/myodc/go-micro/client"
example "github.com/myodc/go-micro/template/proto/example"
2015-01-13 23:31:27 +00:00
)
func main() {
// Create new request to service go.micro.service.go-template, method Example.Call
req := client.NewRequest("go.micro.service.template", "Example.Call", &example.Request{
2015-05-09 00:42:07 +01:00
Name: "John",
2015-01-13 23:31:27 +00:00
})
// 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
}
2015-05-09 00:42:07 +01:00
fmt.Println(rsp.Msg)
2015-01-13 23:31:27 +00:00
}