gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/network/network.go (about)

     1  // Package network is for creating internetworks
     2  package network
     3  
     4  import (
     5  	"time"
     6  
     7  	"gitee.com/liuxuezhan/go-micro-v1.18.0/client"
     8  	"gitee.com/liuxuezhan/go-micro-v1.18.0/server"
     9  )
    10  
    11  var (
    12  	// DefaultName is default network name
    13  	DefaultName = "go.micro"
    14  	// DefaultAddress is default network address
    15  	DefaultAddress = ":0"
    16  	// ResolveTime defines time interval to periodically resolve network nodes
    17  	ResolveTime = 1 * time.Minute
    18  	// AnnounceTime defines time interval to periodically announce node neighbours
    19  	AnnounceTime = 30 * time.Second
    20  	// PruneTime defines time interval to periodically check nodes that need to be pruned
    21  	// due to their not announcing their presence within this time interval
    22  	PruneTime = 90 * time.Second
    23  )
    24  
    25  // Node is network node
    26  type Node interface {
    27  	// Id is node id
    28  	Id() string
    29  	// Address is node bind address
    30  	Address() string
    31  	// Peers returns node peers
    32  	Peers() []Node
    33  	// Network is the network node is in
    34  	Network() Network
    35  }
    36  
    37  // Network is micro network
    38  type Network interface {
    39  	// Node is network node
    40  	Node
    41  	// Initialise options
    42  	Init(...Option) error
    43  	// Options returns the network options
    44  	Options() Options
    45  	// Name of the network
    46  	Name() string
    47  	// Connect starts the resolver and tunnel server
    48  	Connect() error
    49  	// Close stops the tunnel and resolving
    50  	Close() error
    51  	// Client is micro client
    52  	Client() client.Client
    53  	// Server is micro server
    54  	Server() server.Server
    55  }
    56  
    57  // NewNetwork returns a new network interface
    58  func NewNetwork(opts ...Option) Network {
    59  	return newNetwork(opts...)
    60  }