From 4977aca09cb4f5f78e0fa269e997532332ce9547 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 12 Dec 2020 19:04:19 +0000 Subject: [PATCH] move router --- client/selector/router/router.go | 2 +- cmd/cmd.go | 16 ++++++++-------- config/source/cli/cli_test.go | 2 +- network/default.go | 4 ++-- network/options.go | 8 ++++---- network/proxy/mucp/mucp.go | 2 +- network/proxy/options.go | 2 +- {router => network/router}/default.go | 0 {router => network/router}/default_test.go | 0 {router => network/router}/options.go | 0 {router => network/router}/query.go | 0 {router => network/router}/route.go | 0 {router => network/router}/route_test.go | 0 {router => network/router}/router.go | 0 {router => network/router}/table.go | 0 {router => network/router}/table_test.go | 0 {router => network/router}/watcher.go | 0 network/util.go | 2 +- options.go | 3 +-- service.go | 8 -------- transport/quic/quic.go | 2 +- 21 files changed, 21 insertions(+), 30 deletions(-) rename {router => network/router}/default.go (100%) rename {router => network/router}/default_test.go (100%) rename {router => network/router}/options.go (100%) rename {router => network/router}/query.go (100%) rename {router => network/router}/route.go (100%) rename {router => network/router}/route_test.go (100%) rename {router => network/router}/router.go (100%) rename {router => network/router}/table.go (100%) rename {router => network/router}/table_test.go (100%) rename {router => network/router}/watcher.go (100%) diff --git a/client/selector/router/router.go b/client/selector/router/router.go index e865f39f..6b57d87a 100644 --- a/client/selector/router/router.go +++ b/client/selector/router/router.go @@ -7,8 +7,8 @@ import ( "sync" "github.com/micro/go-micro/v2/client/selector" + "github.com/micro/go-micro/v2/network/router" "github.com/micro/go-micro/v2/registry" - "github.com/micro/go-micro/v2/router" ) type routerSelector struct { diff --git a/cmd/cmd.go b/cmd/cmd.go index 64ff829b..98b082c0 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -321,9 +321,9 @@ var ( } DefaultBrokers = map[string]func(...broker.Option) broker.Broker{ - "memory": memory.NewBroker, - "nats": nats.NewBroker, - "http": brokerHttp.NewBroker, + "memory": memory.NewBroker, + "nats": nats.NewBroker, + "http": brokerHttp.NewBroker, } DefaultClients = map[string]func(...client.Option) client.Client{ @@ -332,9 +332,9 @@ var ( } DefaultRegistries = map[string]func(...registry.Option) registry.Registry{ - "etcd": etcd.NewRegistry, - "mdns": mdns.NewRegistry, - "memory": rmem.NewRegistry, + "etcd": etcd.NewRegistry, + "mdns": mdns.NewRegistry, + "memory": rmem.NewRegistry, } DefaultSelectors = map[string]func(...selector.Option) selector.Selector{ @@ -359,7 +359,7 @@ var ( } DefaultStores = map[string]func(...store.Option) store.Store{ - "memory": memStore.NewStore, + "memory": memStore.NewStore, } DefaultTracers = map[string]func(...trace.Option) trace.Tracer{ @@ -368,7 +368,7 @@ var ( } DefaultAuths = map[string]func(...auth.Option) auth.Auth{ - "jwt": jwtAuth.NewAuth, + "jwt": jwtAuth.NewAuth, } DefaultAuthProviders = map[string]func(...provider.Option) provider.Provider{ diff --git a/config/source/cli/cli_test.go b/config/source/cli/cli_test.go index 68458aa3..154faeab 100644 --- a/config/source/cli/cli_test.go +++ b/config/source/cli/cli_test.go @@ -7,8 +7,8 @@ import ( "github.com/micro/cli/v2" "github.com/micro/go-micro/v2" - "github.com/micro/go-micro/v2/config" "github.com/micro/go-micro/v2/cmd" + "github.com/micro/go-micro/v2/config" "github.com/micro/go-micro/v2/config/source" ) diff --git a/network/default.go b/network/default.go index a8b285d1..376b768e 100644 --- a/network/default.go +++ b/network/default.go @@ -17,12 +17,12 @@ import ( rtr "github.com/micro/go-micro/v2/client/selector/router" "github.com/micro/go-micro/v2/logger" pbNet "github.com/micro/go-micro/v2/network/proto" + "github.com/micro/go-micro/v2/network/proxy" "github.com/micro/go-micro/v2/network/resolver/dns" + "github.com/micro/go-micro/v2/network/router" "github.com/micro/go-micro/v2/network/tunnel" bun "github.com/micro/go-micro/v2/network/tunnel/broker" tun "github.com/micro/go-micro/v2/network/tunnel/transport" - "github.com/micro/go-micro/v2/network/proxy" - "github.com/micro/go-micro/v2/router" "github.com/micro/go-micro/v2/server" smucp "github.com/micro/go-micro/v2/server/mucp" "github.com/micro/go-micro/v2/transport" diff --git a/network/options.go b/network/options.go index 3cb09c60..2f9337c8 100644 --- a/network/options.go +++ b/network/options.go @@ -2,12 +2,12 @@ package network import ( "github.com/google/uuid" - "github.com/micro/go-micro/v2/network/resolver" - "github.com/micro/go-micro/v2/network/resolver/registry" - "github.com/micro/go-micro/v2/network/tunnel" "github.com/micro/go-micro/v2/network/proxy" "github.com/micro/go-micro/v2/network/proxy/mucp" - "github.com/micro/go-micro/v2/router" + "github.com/micro/go-micro/v2/network/resolver" + "github.com/micro/go-micro/v2/network/resolver/registry" + "github.com/micro/go-micro/v2/network/router" + "github.com/micro/go-micro/v2/network/tunnel" ) type Option func(*Options) diff --git a/network/proxy/mucp/mucp.go b/network/proxy/mucp/mucp.go index 8dfa8756..70a64cfe 100644 --- a/network/proxy/mucp/mucp.go +++ b/network/proxy/mucp/mucp.go @@ -18,7 +18,7 @@ import ( "github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/network/proxy" - "github.com/micro/go-micro/v2/router" + "github.com/micro/go-micro/v2/network/router" "github.com/micro/go-micro/v2/server" ) diff --git a/network/proxy/options.go b/network/proxy/options.go index 877d66d5..08d701d0 100644 --- a/network/proxy/options.go +++ b/network/proxy/options.go @@ -3,7 +3,7 @@ package proxy import ( "github.com/micro/go-micro/v2/client" - "github.com/micro/go-micro/v2/router" + "github.com/micro/go-micro/v2/network/router" ) type Options struct { diff --git a/router/default.go b/network/router/default.go similarity index 100% rename from router/default.go rename to network/router/default.go diff --git a/router/default_test.go b/network/router/default_test.go similarity index 100% rename from router/default_test.go rename to network/router/default_test.go diff --git a/router/options.go b/network/router/options.go similarity index 100% rename from router/options.go rename to network/router/options.go diff --git a/router/query.go b/network/router/query.go similarity index 100% rename from router/query.go rename to network/router/query.go diff --git a/router/route.go b/network/router/route.go similarity index 100% rename from router/route.go rename to network/router/route.go diff --git a/router/route_test.go b/network/router/route_test.go similarity index 100% rename from router/route_test.go rename to network/router/route_test.go diff --git a/router/router.go b/network/router/router.go similarity index 100% rename from router/router.go rename to network/router/router.go diff --git a/router/table.go b/network/router/table.go similarity index 100% rename from router/table.go rename to network/router/table.go diff --git a/router/table_test.go b/network/router/table_test.go similarity index 100% rename from router/table_test.go rename to network/router/table_test.go diff --git a/router/watcher.go b/network/router/watcher.go similarity index 100% rename from router/watcher.go rename to network/router/watcher.go diff --git a/network/util.go b/network/util.go index dfabf262..47355556 100644 --- a/network/util.go +++ b/network/util.go @@ -2,7 +2,7 @@ package network import ( pbNet "github.com/micro/go-micro/v2/network/proto" - "github.com/micro/go-micro/v2/router" + "github.com/micro/go-micro/v2/network/router" ) // routeToProto encodes route into protobuf and returns it diff --git a/options.go b/options.go index b2342a23..7fe21132 100644 --- a/options.go +++ b/options.go @@ -9,8 +9,8 @@ import ( "github.com/micro/go-micro/v2/broker" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client/selector" - "github.com/micro/go-micro/v2/config" "github.com/micro/go-micro/v2/cmd" + "github.com/micro/go-micro/v2/config" "github.com/micro/go-micro/v2/debug/profile" "github.com/micro/go-micro/v2/debug/trace" "github.com/micro/go-micro/v2/registry" @@ -155,7 +155,6 @@ func Tracer(t trace.Tracer) Option { func Auth(a auth.Auth) Option { return func(o *Options) { o.Auth = a - o.Server.Init(server.Auth(a)) } } diff --git a/service.go b/service.go index 440939f4..3e198938 100644 --- a/service.go +++ b/service.go @@ -7,7 +7,6 @@ import ( "strings" "sync" - "github.com/micro/go-micro/v2/auth" "github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/cmd" "github.com/micro/go-micro/v2/debug/service/handler" @@ -34,21 +33,14 @@ func newService(opts ...Option) Service { // service name serviceName := options.Server.Options().Name - // we pass functions to the wrappers since the values can change during initialisation - authFn := func() auth.Auth { return options.Server.Options().Auth } - cacheFn := func() *client.Cache { return options.Client.Options().Cache } - // wrap client to inject From-Service header on any calls options.Client = wrapper.FromService(serviceName, options.Client) options.Client = wrapper.TraceCall(serviceName, trace.DefaultTracer, options.Client) - options.Client = wrapper.CacheClient(cacheFn, options.Client) - options.Client = wrapper.AuthClient(authFn, options.Client) // wrap the server to provide handler stats options.Server.Init( server.WrapHandler(wrapper.HandlerStats(stats.DefaultStats)), server.WrapHandler(wrapper.TraceHandler(trace.DefaultTracer)), - server.WrapHandler(wrapper.AuthHandler(authFn)), ) // set opts diff --git a/transport/quic/quic.go b/transport/quic/quic.go index 73afcc47..ba212d7b 100644 --- a/transport/quic/quic.go +++ b/transport/quic/quic.go @@ -119,7 +119,7 @@ func (q *quicTransport) Dial(addr string, opts ...transport.DialOption) (transpo } s, err := quic.DialAddr(addr, config, &quic.Config{ MaxIdleTimeout: time.Minute * 2, - KeepAlive: true, + KeepAlive: true, }) if err != nil { return nil, err