micro/transport/transport.go

41 lines
671 B
Go
Raw Normal View History

2015-05-21 00:57:19 +03:00
package transport
type Message struct {
Header map[string]string
Body []byte
}
type Socket interface {
2015-05-21 23:08:19 +03:00
Recv(*Message) error
Send(*Message) error
Close() error
2015-05-21 00:57:19 +03:00
}
type Client interface {
Send(*Message) (*Message, error)
Close() error
}
2015-05-21 23:08:19 +03:00
type Listener interface {
2015-05-21 00:57:19 +03:00
Addr() string
Close() error
2015-05-21 23:08:19 +03:00
Accept(func(Socket)) error
2015-05-21 00:57:19 +03:00
}
type Transport interface {
2015-05-21 23:08:19 +03:00
Dial(addr string) (Client, error)
Listen(addr string) (Listener, error)
2015-05-21 00:57:19 +03:00
}
var (
DefaultTransport Transport = NewHttpTransport([]string{})
)
2015-05-21 23:08:19 +03:00
func Dial(addr string) (Client, error) {
return DefaultTransport.Dial(addr)
2015-05-21 00:57:19 +03:00
}
2015-05-21 23:08:19 +03:00
func Listen(addr string) (Listener, error) {
return DefaultTransport.Listen(addr)
2015-05-21 00:57:19 +03:00
}