Move transport to network/transport
This commit is contained in:
56
network/transport/transport.go
Normal file
56
network/transport/transport.go
Normal file
@@ -0,0 +1,56 @@
|
||||
// Package transport is an interface for synchronous communication
|
||||
package transport
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
Header map[string]string
|
||||
Body []byte
|
||||
}
|
||||
|
||||
type Socket interface {
|
||||
Recv(*Message) error
|
||||
Send(*Message) error
|
||||
Close() error
|
||||
Local() string
|
||||
Remote() string
|
||||
}
|
||||
|
||||
type Client interface {
|
||||
Socket
|
||||
}
|
||||
|
||||
type Listener interface {
|
||||
Addr() string
|
||||
Close() error
|
||||
Accept(func(Socket)) error
|
||||
}
|
||||
|
||||
// Transport is an interface which is used for communication between
|
||||
// services. It uses socket send/recv semantics and had various
|
||||
// implementations {HTTP, RabbitMQ, NATS, ...}
|
||||
type Transport interface {
|
||||
Init(...Option) error
|
||||
Options() Options
|
||||
Dial(addr string, opts ...DialOption) (Client, error)
|
||||
Listen(addr string, opts ...ListenOption) (Listener, error)
|
||||
String() string
|
||||
}
|
||||
|
||||
type Option func(*Options)
|
||||
|
||||
type DialOption func(*DialOptions)
|
||||
|
||||
type ListenOption func(*ListenOptions)
|
||||
|
||||
var (
|
||||
DefaultTransport Transport = newHTTPTransport()
|
||||
|
||||
DefaultDialTimeout = time.Second * 5
|
||||
)
|
||||
|
||||
func NewTransport(opts ...Option) Transport {
|
||||
return newHTTPTransport(opts...)
|
||||
}
|
Reference in New Issue
Block a user