2015-05-21 00:57:19 +03:00
|
|
|
package transport
|
|
|
|
|
|
|
|
type Message struct {
|
|
|
|
Header map[string]string
|
|
|
|
Body []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
type Socket interface {
|
|
|
|
Recv() (*Message, error)
|
|
|
|
WriteHeader(string, string)
|
|
|
|
Write([]byte) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Client interface {
|
|
|
|
Send(*Message) (*Message, error)
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Server interface {
|
|
|
|
Addr() string
|
|
|
|
Close() error
|
|
|
|
Serve(func(Socket)) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Transport interface {
|
2015-05-21 21:24:57 +03:00
|
|
|
NewClient(addr string) (Client, error)
|
|
|
|
NewServer(addr string) (Server, error)
|
2015-05-21 00:57:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
DefaultTransport Transport = NewHttpTransport([]string{})
|
|
|
|
)
|
|
|
|
|
2015-05-21 21:24:57 +03:00
|
|
|
func NewClient(addr string) (Client, error) {
|
|
|
|
return DefaultTransport.NewClient(addr)
|
2015-05-21 00:57:19 +03:00
|
|
|
}
|
|
|
|
|
2015-05-21 21:24:57 +03:00
|
|
|
func NewServer(addr string) (Server, error) {
|
|
|
|
return DefaultTransport.NewServer(addr)
|
2015-05-21 00:57:19 +03:00
|
|
|
}
|