github.com/annwntech/go-micro/v2@v2.9.5/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 type Message struct { 20 Header map[string]string 21 Body []byte 22 } 23 24 type Socket interface { 25 Recv(*Message) error 26 Send(*Message) error 27 Close() error 28 Local() string 29 Remote() string 30 } 31 32 type Client interface { 33 Socket 34 } 35 36 type Listener interface { 37 Addr() string 38 Close() error 39 Accept(func(Socket)) error 40 } 41 42 type Option func(*Options) 43 44 type DialOption func(*DialOptions) 45 46 type ListenOption func(*ListenOptions) 47 48 var ( 49 DefaultTransport Transport = newHTTPTransport() 50 51 DefaultDialTimeout = time.Second * 5 52 ) 53 54 func NewTransport(opts ...Option) Transport { 55 return newHTTPTransport(opts...) 56 }