2019-07-07 16:04:07 +02:00
|
|
|
// Package transport is an interface for synchronous connection based communication
|
2015-05-20 23:57:19 +02:00
|
|
|
package transport
|
|
|
|
|
2016-01-03 23:25:03 +02:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2019-07-07 16:03:08 +02:00
|
|
|
// Transport is an interface which is used for communication between
|
|
|
|
// services. It uses connection based socket send/recv semantics and
|
|
|
|
// has various implementations; http, grpc, quic.
|
|
|
|
type Transport interface {
|
|
|
|
Init(...Option) error
|
|
|
|
Options() Options
|
|
|
|
Dial(addr string, opts ...DialOption) (Client, error)
|
|
|
|
Listen(addr string, opts ...ListenOption) (Listener, error)
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
2015-05-20 23:57:19 +02:00
|
|
|
type Message struct {
|
|
|
|
Header map[string]string
|
|
|
|
Body []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
type Socket interface {
|
2015-05-21 22:08:19 +02:00
|
|
|
Recv(*Message) error
|
|
|
|
Send(*Message) error
|
|
|
|
Close() error
|
2018-11-14 21:49:04 +02:00
|
|
|
Local() string
|
|
|
|
Remote() string
|
2015-05-20 23:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type Client interface {
|
2016-11-05 13:44:02 +02:00
|
|
|
Socket
|
2015-05-20 23:57:19 +02:00
|
|
|
}
|
|
|
|
|
2015-05-21 22:08:19 +02:00
|
|
|
type Listener interface {
|
2015-05-20 23:57:19 +02:00
|
|
|
Addr() string
|
|
|
|
Close() error
|
2015-05-21 22:08:19 +02:00
|
|
|
Accept(func(Socket)) error
|
2015-05-20 23:57:19 +02:00
|
|
|
}
|
|
|
|
|
2015-12-31 20:11:46 +02:00
|
|
|
type Option func(*Options)
|
2015-05-23 21:04:16 +02:00
|
|
|
|
2015-12-31 20:11:46 +02:00
|
|
|
type DialOption func(*DialOptions)
|
2015-06-01 19:55:27 +02:00
|
|
|
|
2016-01-18 02:10:04 +02:00
|
|
|
type ListenOption func(*ListenOptions)
|
|
|
|
|
2015-05-20 23:57:19 +02:00
|
|
|
var (
|
2020-12-29 17:49:26 +02:00
|
|
|
DefaultTransport Transport = NewHTTPTransport()
|
2016-01-03 23:25:03 +02:00
|
|
|
|
|
|
|
DefaultDialTimeout = time.Second * 5
|
2015-05-20 23:57:19 +02:00
|
|
|
)
|