mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-18 08:26:38 +02:00
54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
// Package transport is an interface for synchronous connection based communication
|
|
package transport
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// 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
|
|
}
|
|
|
|
// Message is a broker message.
|
|
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
|
|
}
|
|
|
|
type Option func(*Options)
|
|
|
|
type DialOption func(*DialOptions)
|
|
|
|
type ListenOption func(*ListenOptions)
|
|
|
|
var (
|
|
DefaultTransport Transport = NewHTTPTransport()
|
|
|
|
DefaultDialTimeout = time.Second * 5
|
|
)
|