micro/transport/transport.go

41 lines
741 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 {
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 {
NewClient(name, addr string) (Client, error)
NewServer(name, addr string) (Server, error)
}
var (
DefaultTransport Transport = NewHttpTransport([]string{})
)
func NewClient(name, addr string) (Client, error) {
return DefaultTransport.NewClient(name, addr)
}
func NewServer(name, addr string) (Server, error) {
return DefaultTransport.NewServer(name, addr)
}