add support for streaming requests. cleanup watcher initilisation

This commit is contained in:
Asim
2015-06-01 18:55:27 +01:00
parent fa2c27b64f
commit 09c784d294
25 changed files with 729 additions and 384 deletions

View File

@@ -1,6 +1,7 @@
package client
import (
"github.com/myodc/go-micro/registry"
"github.com/myodc/go-micro/transport"
"golang.org/x/net/context"
)
@@ -11,9 +12,18 @@ type Client interface {
NewJsonRequest(string, string, interface{}) Request
Call(context.Context, Request, interface{}) error
CallRemote(context.Context, string, Request, interface{}) error
Stream(context.Context, Request, interface{}) (Streamer, error)
StreamRemote(context.Context, string, Request, interface{}) (Streamer, error)
}
type Streamer interface {
Request() Request
Error() error
Close() error
}
type options struct {
registry registry.Registry
transport transport.Transport
}
@@ -23,6 +33,12 @@ var (
DefaultClient Client = newRpcClient()
)
func Registry(r registry.Registry) Option {
return func(o *options) {
o.registry = r
}
}
func Transport(t transport.Transport) Option {
return func(o *options) {
o.transport = t
@@ -37,6 +53,14 @@ func CallRemote(ctx context.Context, address string, request Request, response i
return DefaultClient.CallRemote(ctx, address, request, response)
}
func Stream(ctx context.Context, request Request, responseChan interface{}) (Streamer, error) {
return DefaultClient.Stream(ctx, request, responseChan)
}
func StreamRemote(ctx context.Context, address string, request Request, responseChan interface{}) (Streamer, error) {
return DefaultClient.StreamRemote(ctx, address, request, responseChan)
}
func NewClient(opt ...Option) Client {
return newRpcClient(opt...)
}