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 transport
type Message struct {
Id string
Header map[string]string
Body []byte
}
@@ -12,7 +13,8 @@ type Socket interface {
}
type Client interface {
Send(*Message) (*Message, error)
Recv(*Message) error
Send(*Message) error
Close() error
}
@@ -23,24 +25,36 @@ type Listener interface {
}
type Transport interface {
Dial(addr string) (Client, error)
Dial(addr string, opts ...DialOption) (Client, error)
Listen(addr string) (Listener, error)
}
type options struct{}
type dialOptions struct {
stream bool
}
type Option func(*options)
type DialOption func(*dialOptions)
var (
DefaultTransport Transport = newHttpTransport([]string{})
)
func WithStream() DialOption {
return func(o *dialOptions) {
o.stream = true
}
}
func NewTransport(addrs []string, opt ...Option) Transport {
return newHttpTransport(addrs, opt...)
}
func Dial(addr string) (Client, error) {
return DefaultTransport.Dial(addr)
func Dial(addr string, opts ...DialOption) (Client, error) {
return DefaultTransport.Dial(addr, opts...)
}
func Listen(addr string) (Listener, error) {