micro/network/transport/transport.go

64 lines
1.4 KiB
Go
Raw Normal View History

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