v3 refactor (#1868)
* Move to v3 Co-authored-by: Ben Toogood <bentoogood@gmail.com>
This commit is contained in:
parent
c69131b98c
commit
b021fcb130
4
codec.go
4
codec.go
@ -8,8 +8,8 @@ import (
|
||||
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/micro/go-micro/v2/codec"
|
||||
"github.com/micro/go-micro/v2/codec/bytes"
|
||||
"github.com/micro/go-micro/v3/codec"
|
||||
"github.com/micro/go-micro/v3/codec/bytes"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/encoding"
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
@ -3,7 +3,7 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v3/server"
|
||||
)
|
||||
|
||||
func setServerOption(k, v interface{}) server.Option {
|
||||
|
2
error.go
2
error.go
@ -3,7 +3,7 @@ package grpc
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/micro/go-micro/v2/errors"
|
||||
"github.com/micro/go-micro/v3/errors"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v3/registry"
|
||||
)
|
||||
|
||||
func extractValue(v reflect.Type, d int) *registry.Value {
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v3/registry"
|
||||
)
|
||||
|
||||
type testHandler struct{}
|
||||
|
22
grpc.go
22
grpc.go
@ -15,17 +15,17 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
"github.com/micro/go-micro/v2/errors"
|
||||
pberr "github.com/micro/go-micro/v2/errors/proto"
|
||||
"github.com/micro/go-micro/v2/logger"
|
||||
meta "github.com/micro/go-micro/v2/metadata"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v2/util/addr"
|
||||
"github.com/micro/go-micro/v2/util/backoff"
|
||||
mgrpc "github.com/micro/go-micro/v2/util/grpc"
|
||||
mnet "github.com/micro/go-micro/v2/util/net"
|
||||
"github.com/micro/go-micro/v3/broker"
|
||||
"github.com/micro/go-micro/v3/errors"
|
||||
pberr "github.com/micro/go-micro/v3/errors/proto"
|
||||
"github.com/micro/go-micro/v3/logger"
|
||||
meta "github.com/micro/go-micro/v3/metadata"
|
||||
"github.com/micro/go-micro/v3/registry"
|
||||
"github.com/micro/go-micro/v3/server"
|
||||
"github.com/micro/go-micro/v3/util/addr"
|
||||
"github.com/micro/go-micro/v3/util/backoff"
|
||||
mgrpc "github.com/micro/go-micro/v3/util/grpc"
|
||||
mnet "github.com/micro/go-micro/v3/util/net"
|
||||
"golang.org/x/net/netutil"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
40
grpc_test.go
40
grpc_test.go
@ -5,21 +5,20 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/micro/go-micro/v2"
|
||||
bmemory "github.com/micro/go-micro/v2/broker/memory"
|
||||
"github.com/micro/go-micro/v2/client"
|
||||
gcli "github.com/micro/go-micro/v2/client/grpc"
|
||||
"github.com/micro/go-micro/v2/errors"
|
||||
pberr "github.com/micro/go-micro/v2/errors/proto"
|
||||
rmemory "github.com/micro/go-micro/v2/registry/memory"
|
||||
"github.com/micro/go-micro/v2/router"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
gsrv "github.com/micro/go-micro/v2/server/grpc"
|
||||
tgrpc "github.com/micro/go-micro/v2/transport/grpc"
|
||||
bmemory "github.com/micro/go-micro/v3/broker/memory"
|
||||
"github.com/micro/go-micro/v3/client"
|
||||
gcli "github.com/micro/go-micro/v3/client/grpc"
|
||||
"github.com/micro/go-micro/v3/errors"
|
||||
pberr "github.com/micro/go-micro/v3/errors/proto"
|
||||
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"
|
||||
gsrv "github.com/micro/go-micro/v3/server/grpc"
|
||||
pb "github.com/micro/go-micro/v3/server/grpc/proto"
|
||||
tgrpc "github.com/micro/go-micro/v3/transport/grpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
pb "github.com/micro/go-micro/v2/server/grpc/proto"
|
||||
)
|
||||
|
||||
// server is used to implement helloworld.GreeterServer.
|
||||
@ -117,7 +116,7 @@ func TestGRPCServer(t *testing.T) {
|
||||
r := rmemory.NewRegistry()
|
||||
b := bmemory.NewBroker()
|
||||
tr := tgrpc.NewTransport()
|
||||
rtr := router.NewRouter(router.Registry(r))
|
||||
rtr := rtreg.NewRouter(router.Registry(r))
|
||||
|
||||
s := gsrv.NewServer(
|
||||
server.Broker(b),
|
||||
@ -136,10 +135,7 @@ func TestGRPCServer(t *testing.T) {
|
||||
h := &testServer{}
|
||||
pb.RegisterTestHandler(s, h)
|
||||
|
||||
if err := micro.RegisterSubscriber("test_topic", s, h.Handle); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := micro.RegisterSubscriber("error_topic", s, h.HandleError); err != nil {
|
||||
if err := s.Subscribe(s.NewSubscriber("test_topic", h.Handle)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -159,11 +155,10 @@ func TestGRPCServer(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
pub := micro.NewEvent("test_topic", c)
|
||||
pubErr := micro.NewEvent("error_topic", c)
|
||||
cnt := 4
|
||||
for i := 0; i < cnt; i++ {
|
||||
if err = pub.Publish(ctx, &pb.Request{Name: fmt.Sprintf("msg %d", i)}); err != nil {
|
||||
msg := c.NewMessage("test_topic", &pb.Request{Name: fmt.Sprintf("msg %d", i)})
|
||||
if err = c.Publish(ctx, msg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -171,9 +166,6 @@ func TestGRPCServer(t *testing.T) {
|
||||
if h.msgCount != cnt {
|
||||
t.Fatalf("pub/sub not work, or invalid message count %d", h.msgCount)
|
||||
}
|
||||
if err = pubErr.Publish(ctx, &pb.Request{}); err == nil {
|
||||
t.Fatal("this must return error, as we return error from handler")
|
||||
}
|
||||
|
||||
cc, err := grpc.Dial(s.Options().Address, grpc.WithInsecure())
|
||||
if err != nil {
|
||||
|
@ -3,8 +3,8 @@ package grpc
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v3/registry"
|
||||
"github.com/micro/go-micro/v3/server"
|
||||
)
|
||||
|
||||
type rpcHandler struct {
|
||||
|
16
options.go
16
options.go
@ -5,12 +5,11 @@ import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
|
||||
"github.com/micro/go-micro/v2/auth"
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
"github.com/micro/go-micro/v2/codec"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v2/transport"
|
||||
"github.com/micro/go-micro/v3/broker/http"
|
||||
"github.com/micro/go-micro/v3/codec"
|
||||
"github.com/micro/go-micro/v3/registry/mdns"
|
||||
"github.com/micro/go-micro/v3/server"
|
||||
"github.com/micro/go-micro/v3/transport"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/encoding"
|
||||
)
|
||||
@ -67,11 +66,10 @@ func MaxMsgSize(s int) server.Option {
|
||||
|
||||
func newOptions(opt ...server.Option) server.Options {
|
||||
opts := server.Options{
|
||||
Auth: auth.DefaultAuth,
|
||||
Codecs: make(map[string]codec.NewCodec),
|
||||
Metadata: map[string]string{},
|
||||
Broker: broker.DefaultBroker,
|
||||
Registry: registry.DefaultRegistry,
|
||||
Broker: http.NewBroker(),
|
||||
Registry: mdns.NewRegistry(),
|
||||
Transport: transport.DefaultTransport,
|
||||
Address: server.DefaultAddress,
|
||||
Name: server.DefaultName,
|
||||
|
@ -12,9 +12,9 @@ import (
|
||||
|
||||
import (
|
||||
context "context"
|
||||
api "github.com/micro/go-micro/v2/api"
|
||||
client "github.com/micro/go-micro/v2/client"
|
||||
server "github.com/micro/go-micro/v2/server"
|
||||
api "github.com/micro/go-micro/v3/api"
|
||||
client "github.com/micro/go-micro/v3/client"
|
||||
server "github.com/micro/go-micro/v3/server"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
@ -1,8 +1,8 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/v2/codec"
|
||||
"github.com/micro/go-micro/v2/codec/bytes"
|
||||
"github.com/micro/go-micro/v3/codec"
|
||||
"github.com/micro/go-micro/v3/codec/bytes"
|
||||
)
|
||||
|
||||
type rpcRequest struct {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/v2/codec"
|
||||
"github.com/micro/go-micro/v3/codec"
|
||||
)
|
||||
|
||||
type rpcResponse struct {
|
||||
|
@ -14,8 +14,8 @@ import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v3/logger"
|
||||
"github.com/micro/go-micro/v3/server"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -3,7 +3,7 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v3/server"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
"github.com/micro/go-micro/v2/errors"
|
||||
"github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/metadata"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v3/broker"
|
||||
"github.com/micro/go-micro/v3/errors"
|
||||
"github.com/micro/go-micro/v3/logger"
|
||||
"github.com/micro/go-micro/v3/metadata"
|
||||
"github.com/micro/go-micro/v3/registry"
|
||||
"github.com/micro/go-micro/v3/server"
|
||||
)
|
||||
|
||||
const (
|
||||
|
Loading…
Reference in New Issue
Block a user