github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/network/transport/transport.go (about)

     1  // Licensed under the Apache License, Version 2.0 (the "License");
     2  // you may not use this file except in compliance with the License.
     3  // You may obtain a copy of the License at
     4  //
     5  //     https://www.apache.org/licenses/LICENSE-2.0
     6  //
     7  // Unless required by applicable law or agreed to in writing, software
     8  // distributed under the License is distributed on an "AS IS" BASIS,
     9  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    10  // See the License for the specific language governing permissions and
    11  // limitations under the License.
    12  //
    13  // Original source: github.com/micro/go-micro/v3/network/transport/transport.go
    14  
    15  // Package transport is an interface for synchronous connection based communication
    16  package transport
    17  
    18  import (
    19  	"time"
    20  )
    21  
    22  // Transport is an interface which is used for communication between
    23  // services. It uses connection based socket send/recv semantics and
    24  // has various implementations; http, grpc, quic.
    25  type Transport interface {
    26  	Init(...Option) error
    27  	Options() Options
    28  	Dial(addr string, opts ...DialOption) (Client, error)
    29  	Listen(addr string, opts ...ListenOption) (Listener, error)
    30  	String() string
    31  }
    32  
    33  type Message struct {
    34  	Header map[string]string
    35  	Body   []byte
    36  }
    37  
    38  type Socket interface {
    39  	Recv(*Message) error
    40  	Send(*Message) error
    41  	Close() error
    42  	Local() string
    43  	Remote() string
    44  }
    45  
    46  type Client interface {
    47  	Socket
    48  }
    49  
    50  type Listener interface {
    51  	Addr() string
    52  	Close() error
    53  	Accept(func(Socket)) error
    54  }
    55  
    56  type Option func(*Options)
    57  
    58  type DialOption func(*DialOptions)
    59  
    60  type ListenOption func(*ListenOptions)
    61  
    62  var (
    63  	DefaultDialTimeout = time.Second * 5
    64  )