github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/network/network.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/network.go
    14  
    15  // Package network implements micro network node
    16  package network
    17  
    18  import (
    19  	"github.com/tickoalcantara12/micro/v3/service/client"
    20  	"github.com/tickoalcantara12/micro/v3/service/server"
    21  )
    22  
    23  var (
    24  	// DefaultNetwork implementation
    25  	DefaultNetwork Network
    26  )
    27  
    28  // Error is network node errors
    29  type Error interface {
    30  	// Count is current count of errors
    31  	Count() int
    32  	// Msg is last error message
    33  	Msg() string
    34  }
    35  
    36  // Status is node status
    37  type Status interface {
    38  	// Error reports error status
    39  	Error() Error
    40  }
    41  
    42  // Node is network node
    43  type Node interface {
    44  	// Id is node id
    45  	Id() string
    46  	// Address is node bind address
    47  	Address() string
    48  	// Peers returns node peers
    49  	Peers() []Node
    50  	// Network is the network node is in
    51  	Network() Network
    52  	// Status returns node status
    53  	Status() Status
    54  }
    55  
    56  // Network is micro network
    57  type Network interface {
    58  	// Node is network node
    59  	Node
    60  	// Initialise options
    61  	Init(...Option) error
    62  	// Options returns the network options
    63  	Options() Options
    64  	// Name of the network
    65  	Name() string
    66  	// Connect starts the resolver and tunnel server
    67  	Connect() error
    68  	// Close stops the tunnel and resolving
    69  	Close() error
    70  	// Client is micro client
    71  	Client() client.Client
    72  	// Server is micro server
    73  	Server() server.Server
    74  }