micro/examples/client/main.go

37 lines
749 B
Go
Raw Normal View History

2015-01-14 02:31:27 +03:00
package main
import (
"fmt"
2015-05-05 21:05:06 +03:00
"github.com/myodc/go-micro/client"
2015-05-21 21:24:57 +03:00
"github.com/myodc/go-micro/cmd"
2015-05-23 13:53:40 +03:00
c "github.com/myodc/go-micro/context"
2015-05-25 20:16:42 +03:00
example "github.com/myodc/go-micro/examples/server/proto/example"
2015-05-23 13:53:40 +03:00
"golang.org/x/net/context"
2015-01-14 02:31:27 +03:00
)
func main() {
2015-05-21 21:24:57 +03:00
cmd.Init()
2015-05-25 20:16:42 +03:00
// Create new request to service go.micro.srv.example, method Example.Call
req := client.NewRequest("go.micro.srv.example", "Example.Call", &example.Request{
2015-05-09 02:42:07 +03:00
Name: "John",
2015-01-14 02:31:27 +03:00
})
2015-05-23 13:53:40 +03:00
// create context with metadata
ctx := c.WithMetaData(context.Background(), map[string]string{
"X-User-Id": "john",
"X-From-Id": "script",
})
2015-01-14 02:31:27 +03:00
rsp := &example.Response{}
// Call service
2015-05-23 13:53:40 +03:00
if err := client.Call(ctx, req, rsp); err != nil {
2015-01-14 02:31:27 +03:00
fmt.Println(err)
return
}
2015-05-09 02:42:07 +03:00
fmt.Println(rsp.Msg)
2015-01-14 02:31:27 +03:00
}