First commit. Outline of the default network.
This commit is contained in:
parent
718780367e
commit
6beae23afd
50
network/default.go
Normal file
50
network/default.go
Normal file
@ -0,0 +1,50 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/client"
|
||||
"github.com/micro/go-micro/server"
|
||||
)
|
||||
|
||||
// network implements Network interface
|
||||
type network struct {
|
||||
// options configure the network
|
||||
options Options
|
||||
}
|
||||
|
||||
// newNetwork returns a new network node
|
||||
func newNetwork(opts ...Option) Network {
|
||||
options := DefaultOptions()
|
||||
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
return &network{
|
||||
options: options,
|
||||
}
|
||||
}
|
||||
|
||||
// Name returns network name
|
||||
func (n *network) Name() string {
|
||||
return n.options.Name
|
||||
}
|
||||
|
||||
// Connect connects the network
|
||||
func (n *network) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close closes network connection
|
||||
func (n *network) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Client returns network client
|
||||
func (n *network) Client() client.Client {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Server returns network server
|
||||
func (n *network) Server() server.Server {
|
||||
return nil
|
||||
}
|
@ -8,8 +8,13 @@ import (
|
||||
"github.com/micro/go-micro/transport"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrLinkClosed is returned when attempting i/o operation on the closed link
|
||||
ErrLinkClosed = errors.New("link closed")
|
||||
)
|
||||
|
||||
// Link is a layer on top of a transport socket with the
|
||||
// buffering send and recv queue's with the ability to
|
||||
// buffering send and recv queues with the ability to
|
||||
// measure the actual transport link and reconnect if
|
||||
// an address is specified.
|
||||
type Link interface {
|
||||
@ -28,10 +33,6 @@ type Link interface {
|
||||
Length() int
|
||||
}
|
||||
|
||||
var (
|
||||
ErrLinkClosed = errors.New("link closed")
|
||||
)
|
||||
|
||||
// NewLink creates a new link on top of a socket
|
||||
func NewLink(opts ...options.Option) Link {
|
||||
return newLink(options.NewOptions(opts...))
|
||||
|
@ -1,2 +1,33 @@
|
||||
// Package network is for creating internetworks
|
||||
package network
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/client"
|
||||
"github.com/micro/go-micro/server"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultName is default network name
|
||||
DefaultName = "go.micro.network"
|
||||
// DefaultAddress is default network address
|
||||
DefaultAddress = ":0"
|
||||
)
|
||||
|
||||
// Network is micro network
|
||||
type Network interface {
|
||||
// Name of the network
|
||||
Name() string
|
||||
// Connect starts the resolver and tunnel server
|
||||
Connect() error
|
||||
// Close stops the tunnel and resolving
|
||||
Close() error
|
||||
// Client is micro client
|
||||
Client() client.Client
|
||||
// Server is micro server
|
||||
Server() server.Server
|
||||
}
|
||||
|
||||
// NewNetwork returns a new network interface
|
||||
func NewNetwork(opts ...Option) Network {
|
||||
return newNetwork(opts...)
|
||||
}
|
||||
|
48
network/options.go
Normal file
48
network/options.go
Normal file
@ -0,0 +1,48 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/network/resolver"
|
||||
"github.com/micro/go-micro/network/resolver/dns"
|
||||
)
|
||||
|
||||
type Option func(*Options)
|
||||
|
||||
// Options configure network
|
||||
type Options struct {
|
||||
// Name of the network
|
||||
Name string
|
||||
// Address to bind to
|
||||
Address string
|
||||
// Resolver is network resolver
|
||||
Resolver resolver.Resolver
|
||||
}
|
||||
|
||||
// Name is the network name
|
||||
func Name(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
||||
// Address is the network address
|
||||
func Address(a string) Option {
|
||||
return func(o *Options) {
|
||||
o.Address = a
|
||||
}
|
||||
}
|
||||
|
||||
// Resolver is the network resolver
|
||||
func Resolver(r resolver.Resolver) Option {
|
||||
return func(o *Options) {
|
||||
o.Resolver = r
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultOptions returns network default options
|
||||
func DefaultOptions() Options {
|
||||
return Options{
|
||||
Name: DefaultName,
|
||||
Address: DefaultAddress,
|
||||
Resolver: &dns.Resolver{},
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/micro/go-micro/network/resolver"
|
||||
)
|
||||
|
||||
// Resolver is a DNS network resolve
|
||||
type Resolver struct{}
|
||||
|
||||
// Resolve assumes ID is a domain name e.g micro.mu
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/micro/go-micro/network/resolver"
|
||||
)
|
||||
|
||||
// Resolver is a HTTP network resolver
|
||||
type Resolver struct {
|
||||
// If not set, defaults to http
|
||||
Proto string
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/micro/go-micro/registry"
|
||||
)
|
||||
|
||||
// Resolver is a registry network resolver
|
||||
type Resolver struct {
|
||||
// Registry is the registry to use otherwise we use the defaul
|
||||
Registry registry.Registry
|
||||
|
@ -5,7 +5,7 @@ package resolver
|
||||
// via the name to connect to. This is done based on Network.Name().
|
||||
// Before we can be part of any network, we have to connect to it.
|
||||
type Resolver interface {
|
||||
// Resolve returns a list of addresses for an name
|
||||
// Resolve returns a list of addresses for a name
|
||||
Resolve(name string) ([]*Record, error)
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,17 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultAddress is default router address
|
||||
DefaultAddress = ":9093"
|
||||
// DefaultName is default router service name
|
||||
DefaultName = "go.micro.router"
|
||||
// DefaultNetwork is default micro network
|
||||
DefaultNetwork = "go.micro"
|
||||
// DefaultRouter is default network router
|
||||
DefaultRouter = NewRouter()
|
||||
)
|
||||
|
||||
// Router is an interface for a routing control plane
|
||||
type Router interface {
|
||||
// Init initializes the router with options
|
||||
@ -125,17 +136,6 @@ type Advert struct {
|
||||
Events []*Event
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultAddress is default router address
|
||||
DefaultAddress = ":9093"
|
||||
// DefaultName is default router service name
|
||||
DefaultName = "go.micro.router"
|
||||
// DefaultNetwork is default micro network
|
||||
DefaultNetwork = "go.micro"
|
||||
// DefaultRouter is default network router
|
||||
DefaultRouter = NewRouter()
|
||||
)
|
||||
|
||||
// NewRouter creates new Router and returns it
|
||||
func NewRouter(opts ...Option) Router {
|
||||
return newRouter(opts...)
|
||||
|
Loading…
Reference in New Issue
Block a user