go-micro.dev/v5@v5.12.0/transport/transport.go (about) 1 // Package transport is an interface for synchronous connection based communication 2 package transport 3 4 import ( 5 "time" 6 ) 7 8 // Transport is an interface which is used for communication between 9 // services. It uses connection based socket send/recv semantics and 10 // has various implementations; http, grpc, quic. 11 type Transport interface { 12 Init(...Option) error 13 Options() Options 14 Dial(addr string, opts ...DialOption) (Client, error) 15 Listen(addr string, opts ...ListenOption) (Listener, error) 16 String() string 17 } 18 19 // Message is a broker message. 20 type Message struct { 21 Header map[string]string 22 Body []byte 23 } 24 25 type Socket interface { 26 Recv(*Message) error 27 Send(*Message) error 28 Close() error 29 Local() string 30 Remote() string 31 } 32 33 type Client interface { 34 Socket 35 } 36 37 type Listener interface { 38 Addr() string 39 Close() error 40 Accept(func(Socket)) error 41 } 42 43 type Option func(*Options) 44 45 type DialOption func(*DialOptions) 46 47 type ListenOption func(*ListenOptions) 48 49 var ( 50 DefaultTransport Transport = NewHTTPTransport() 51 52 DefaultDialTimeout = time.Second * 5 53 )