Add proxy/router

This commit is contained in:
Asim Aslam 2019-07-31 15:30:51 +01:00
parent fca89e06ef
commit 3e90d32f29
2 changed files with 25 additions and 0 deletions

View File

@ -2,6 +2,8 @@ package network
import ( import (
"github.com/micro/go-micro/client" "github.com/micro/go-micro/client"
"github.com/micro/go-micro/network/proxy/mucp"
"github.com/micro/go-micro/network/router"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
) )
@ -28,6 +30,8 @@ func NewNetwork(opts ...Option) Network {
Name: DefaultName, Name: DefaultName,
Client: client.DefaultClient, Client: client.DefaultClient,
Server: server.DefaultServer, Server: server.DefaultServer,
Proxy: mucp.NewProxy(),
Router: router.DefaultRouter,
} }
for _, o := range opts { for _, o := range opts {
@ -37,6 +41,7 @@ func NewNetwork(opts ...Option) Network {
// set the server name // set the server name
options.Server.Init( options.Server.Init(
server.Name(options.Name), server.Name(options.Name),
server.WithRouter(options.Proxy),
) )
return &network{ return &network{

View File

@ -2,6 +2,8 @@ package network
import ( import (
"github.com/micro/go-micro/client" "github.com/micro/go-micro/client"
"github.com/micro/go-micro/network/proxy"
"github.com/micro/go-micro/network/router"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
) )
@ -11,6 +13,8 @@ type Options struct {
Name string Name string
Client client.Client Client client.Client
Server server.Server Server server.Server
Proxy proxy.Proxy
Router router.Router
} }
// The network name // The network name
@ -33,3 +37,19 @@ func Server(s server.Server) Option {
o.Server = s o.Server = s
} }
} }
// The proxy to use
func Proxy(p proxy.Proxy) Option {
return func(o *Options) {
o.Proxy = p
}
}
// The router to use
func Router(r router.Router) Option {
return func(o *Options) {
o.Router = r
}
}