v3 refactor (#1868)
* Move to v3 Co-authored-by: Ben Toogood <bentoogood@gmail.com>
This commit is contained in:
@@ -5,13 +5,13 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/micro/go-micro/v2/auth"
|
||||
"github.com/micro/go-micro/v2/client"
|
||||
"github.com/micro/go-micro/v2/debug/stats"
|
||||
"github.com/micro/go-micro/v2/debug/trace"
|
||||
"github.com/micro/go-micro/v2/errors"
|
||||
"github.com/micro/go-micro/v2/metadata"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v3/auth"
|
||||
"github.com/micro/go-micro/v3/client"
|
||||
"github.com/micro/go-micro/v3/debug/stats"
|
||||
"github.com/micro/go-micro/v3/debug/trace"
|
||||
"github.com/micro/go-micro/v3/errors"
|
||||
"github.com/micro/go-micro/v3/metadata"
|
||||
"github.com/micro/go-micro/v3/server"
|
||||
)
|
||||
|
||||
type fromServiceWrapper struct {
|
||||
@@ -313,7 +313,7 @@ func (c *cacheWrapper) Call(ctx context.Context, req client.Request, rsp interfa
|
||||
}
|
||||
|
||||
// check to see if there is a response cached, if there is assign it
|
||||
if r, ok := cache.Get(ctx, &req); ok {
|
||||
if r, ok := cache.Get(ctx, req); ok {
|
||||
val := reflect.ValueOf(rsp).Elem()
|
||||
val.Set(reflect.ValueOf(r).Elem())
|
||||
return nil
|
||||
@@ -325,7 +325,7 @@ func (c *cacheWrapper) Call(ctx context.Context, req client.Request, rsp interfa
|
||||
}
|
||||
|
||||
// set the result in the cache
|
||||
cache.Set(ctx, &req, rsp, options.CacheExpiry)
|
||||
cache.Set(ctx, req, rsp, options.CacheExpiry)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -4,14 +4,17 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
bmemory "github.com/micro/go-micro/v2/broker/memory"
|
||||
"github.com/micro/go-micro/v2/client"
|
||||
rmemory "github.com/micro/go-micro/v2/registry/memory"
|
||||
"github.com/micro/go-micro/v2/router"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
tmemory "github.com/micro/go-micro/v2/transport/memory"
|
||||
wrapper "github.com/micro/go-micro/v2/util/wrapper"
|
||||
"github.com/micro/go-micro/v3/broker"
|
||||
bmemory "github.com/micro/go-micro/v3/broker/memory"
|
||||
"github.com/micro/go-micro/v3/client"
|
||||
"github.com/micro/go-micro/v3/client/grpc"
|
||||
rmemory "github.com/micro/go-micro/v3/registry/memory"
|
||||
"github.com/micro/go-micro/v3/router"
|
||||
rtreg "github.com/micro/go-micro/v3/router/registry"
|
||||
"github.com/micro/go-micro/v3/server"
|
||||
grpcsrv "github.com/micro/go-micro/v3/server/grpc"
|
||||
tmemory "github.com/micro/go-micro/v3/transport/memory"
|
||||
wrapper "github.com/micro/go-micro/v3/util/wrapper"
|
||||
)
|
||||
|
||||
type TestFoo struct {
|
||||
@@ -31,15 +34,20 @@ func (h *TestFoo) Bar(ctx context.Context, req *TestReq, rsp *TestRsp) error {
|
||||
func TestStaticClientWrapper(t *testing.T) {
|
||||
var err error
|
||||
|
||||
req := client.NewRequest("go.micro.service.foo", "TestFoo.Bar", &TestReq{}, client.WithContentType("application/json"))
|
||||
req := grpc.NewClient().NewRequest(
|
||||
"go.micro.service.foo",
|
||||
"TestFoo.Bar",
|
||||
&TestReq{},
|
||||
client.WithContentType("application/json"),
|
||||
)
|
||||
rsp := &TestRsp{}
|
||||
|
||||
reg := rmemory.NewRegistry()
|
||||
brk := bmemory.NewBroker(broker.Registry(reg))
|
||||
tr := tmemory.NewTransport()
|
||||
rtr := router.NewRouter(router.Registry(reg))
|
||||
rtr := rtreg.NewRouter(router.Registry(reg))
|
||||
|
||||
srv := server.NewServer(
|
||||
srv := grpcsrv.NewServer(
|
||||
server.Broker(brk),
|
||||
server.Registry(reg),
|
||||
server.Name("go.micro.service.foo"),
|
||||
@@ -54,7 +62,7 @@ func TestStaticClientWrapper(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cli := client.NewClient(
|
||||
cli := grpc.NewClient(
|
||||
client.Router(rtr),
|
||||
client.Broker(brk),
|
||||
client.Transport(tr),
|
||||
|
@@ -7,11 +7,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/v2/auth"
|
||||
"github.com/micro/go-micro/v2/client"
|
||||
"github.com/micro/go-micro/v2/errors"
|
||||
"github.com/micro/go-micro/v2/metadata"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v3/auth"
|
||||
"github.com/micro/go-micro/v3/client"
|
||||
"github.com/micro/go-micro/v3/client/grpc"
|
||||
"github.com/micro/go-micro/v3/errors"
|
||||
"github.com/micro/go-micro/v3/metadata"
|
||||
"github.com/micro/go-micro/v3/server"
|
||||
)
|
||||
|
||||
func TestWrapper(t *testing.T) {
|
||||
@@ -371,7 +372,7 @@ type testRsp struct {
|
||||
}
|
||||
|
||||
func TestCacheWrapper(t *testing.T) {
|
||||
req := client.NewRequest("go.micro.service.foo", "Foo.Bar", nil)
|
||||
req := grpc.NewClient().NewRequest("go.micro.service.foo", "Foo.Bar", nil)
|
||||
|
||||
t.Run("NilCache", func(t *testing.T) {
|
||||
cli := new(testClient)
|
||||
|
Reference in New Issue
Block a user