2019-07-07 15:04:07 +01:00
|
|
|
// Package transport is an interface for synchronous connection based communication
|
2021-10-02 19:55:07 +03:00
|
|
|
package transport // import "go.unistack.org/micro/v3/network/transport"
|
2015-05-20 22:57:19 +01:00
|
|
|
|
2016-01-03 21:25:03 +00:00
|
|
|
import (
|
2020-11-03 02:02:32 +03:00
|
|
|
"context"
|
2016-01-03 21:25:03 +00:00
|
|
|
"time"
|
2020-11-18 16:50:41 +03:00
|
|
|
|
2021-10-02 19:55:07 +03:00
|
|
|
"go.unistack.org/micro/v3/metadata"
|
2016-01-03 21:25:03 +00:00
|
|
|
)
|
|
|
|
|
2020-08-28 11:52:51 +03:00
|
|
|
var (
|
2020-11-03 01:08:23 +03:00
|
|
|
// DefaultTransport is the global default transport
|
|
|
|
DefaultTransport Transport = NewTransport()
|
2021-02-14 16:16:01 +03:00
|
|
|
// DefaultDialTimeout the default dial timeout
|
2020-11-06 11:18:12 +03:00
|
|
|
DefaultDialTimeout = time.Second * 5
|
2020-08-28 11:52:51 +03:00
|
|
|
)
|
|
|
|
|
2019-07-07 15:03:08 +01: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
|
2020-11-03 02:02:32 +03:00
|
|
|
Dial(ctx context.Context, addr string, opts ...DialOption) (Client, error)
|
|
|
|
Listen(ctx context.Context, addr string, opts ...ListenOption) (Listener, error)
|
2019-07-07 15:03:08 +01:00
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:33:36 +03:00
|
|
|
// Message is used to transfer data
|
2015-05-20 22:57:19 +01:00
|
|
|
type Message struct {
|
2020-11-18 16:50:41 +03:00
|
|
|
Header metadata.Metadata
|
2015-05-20 22:57:19 +01:00
|
|
|
Body []byte
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:33:36 +03:00
|
|
|
// Socket bastraction interface
|
2015-05-20 22:57:19 +01:00
|
|
|
type Socket interface {
|
2015-05-21 21:08:19 +01:00
|
|
|
Recv(*Message) error
|
|
|
|
Send(*Message) error
|
|
|
|
Close() error
|
2018-11-14 19:49:04 +00:00
|
|
|
Local() string
|
|
|
|
Remote() string
|
2015-05-20 22:57:19 +01:00
|
|
|
}
|
|
|
|
|
2020-08-25 14:33:36 +03:00
|
|
|
// Client is the socket owner
|
2015-05-20 22:57:19 +01:00
|
|
|
type Client interface {
|
2016-11-05 11:44:02 +00:00
|
|
|
Socket
|
2015-05-20 22:57:19 +01:00
|
|
|
}
|
|
|
|
|
2020-08-25 14:33:36 +03:00
|
|
|
// Listener is the interface for stream oriented messaging
|
2015-05-21 21:08:19 +01:00
|
|
|
type Listener interface {
|
2015-05-20 22:57:19 +01:00
|
|
|
Addr() string
|
|
|
|
Close() error
|
2015-05-21 21:08:19 +01:00
|
|
|
Accept(func(Socket)) error
|
2015-05-20 22:57:19 +01:00
|
|
|
}
|
|
|
|
|
2020-08-25 14:33:36 +03:00
|
|
|
// Option is the option signature
|
2015-12-31 18:11:46 +00:00
|
|
|
type Option func(*Options)
|
2015-05-23 20:04:16 +01:00
|
|
|
|
2020-08-25 14:33:36 +03:00
|
|
|
// DialOption is the option signature
|
2015-12-31 18:11:46 +00:00
|
|
|
type DialOption func(*DialOptions)
|
2015-06-01 18:55:27 +01:00
|
|
|
|
2020-08-25 14:33:36 +03:00
|
|
|
// ListenOption is the option signature
|
2016-01-18 00:10:04 +00:00
|
|
|
type ListenOption func(*ListenOptions)
|