Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
356e20440b
commit
4c0469d1f0
@ -17,7 +17,7 @@ type testClient struct {
|
|||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTestClient(name string, c client.Client) proto.TestClient {
|
func NewTestClient(name string, c client.Client) TestClient {
|
||||||
return &testClient{c: c, name: name}
|
return &testClient{c: c, name: name}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ func (c *testClient) Call(ctx context.Context, req *proto.Request, opts ...clien
|
|||||||
return rsp, nil
|
return rsp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testClient) Stream(ctx context.Context, opts ...client.CallOption) (proto.Test_StreamClient, error) {
|
func (c *testClient) Stream(ctx context.Context, opts ...client.CallOption) (Test_StreamClient, error) {
|
||||||
stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "Test.Stream", &proto.Request{}), opts...)
|
stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "Test.Stream", &proto.Request{}), opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -91,7 +91,7 @@ func (s *testClientStream) Recv() (*proto.Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type testServer struct {
|
type testServer struct {
|
||||||
proto.TestServer
|
TestServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *testServer) Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error {
|
func (h *testServer) Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error {
|
||||||
@ -141,7 +141,7 @@ func (s *testStreamStream) Recv() (*proto.Request, error) {
|
|||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterTestServer(s server.Server, sh proto.TestServer, opts ...server.HandlerOption) error {
|
func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOption) error {
|
||||||
type test interface {
|
type test interface {
|
||||||
Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error
|
Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error
|
||||||
Stream(ctx context.Context, stream server.Stream) error
|
Stream(ctx context.Context, stream server.Stream) error
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"go.unistack.org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"go.unistack.org/micro/v3/errors"
|
"go.unistack.org/micro/v3/errors"
|
||||||
"go.unistack.org/micro/v3/register"
|
"go.unistack.org/micro/v3/register"
|
||||||
|
mregister "go.unistack.org/micro/v3/register/memory"
|
||||||
"go.unistack.org/micro/v3/router"
|
"go.unistack.org/micro/v3/router"
|
||||||
pgrpc "google.golang.org/grpc"
|
pgrpc "google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
@ -71,7 +72,7 @@ func TestGRPCClient(t *testing.T) {
|
|||||||
defer s.Stop()
|
defer s.Stop()
|
||||||
|
|
||||||
// create mock register
|
// create mock register
|
||||||
r := register.NewRegister()
|
r := mregister.NewRegister()
|
||||||
|
|
||||||
// register service
|
// register service
|
||||||
if err := r.Register(ctx, ®ister.Service{
|
if err := r.Register(ctx, ®ister.Service{
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"go.unistack.org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"go.unistack.org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
"go.unistack.org/micro/v3/register"
|
"go.unistack.org/micro/v3/register"
|
||||||
|
mregister "go.unistack.org/micro/v3/register/memory"
|
||||||
"go.unistack.org/micro/v3/router"
|
"go.unistack.org/micro/v3/router"
|
||||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||||
)
|
)
|
||||||
@ -89,7 +90,7 @@ func TestNativeWithoutPath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPClient(t *testing.T) {
|
func TestHTTPClient(t *testing.T) {
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
rtr := rrouter.NewRouter(router.Register(reg))
|
rtr := rrouter.NewRouter(router.Register(reg))
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
@ -179,7 +180,7 @@ func TestHTTPClient(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPClientStream(t *testing.T) {
|
func TestHTTPClientStream(t *testing.T) {
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
rtr := rrouter.NewRouter(router.Register(reg))
|
rtr := rrouter.NewRouter(router.Register(reg))
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
//go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go_out=paths=source_relative:./proto --go-micro_out=components='micro|http',debug=true,paths=source_relative:./proto proto/test.proto"
|
//go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go_out=paths=source_relative:./proto --go-micro_out=components='micro|grpc',debug=true,paths=source_relative:./proto proto/test.proto"
|
||||||
|
@ -9,21 +9,17 @@ import (
|
|||||||
protocodec "go.unistack.org/micro-codec-segmentio/v3/proto"
|
protocodec "go.unistack.org/micro-codec-segmentio/v3/proto"
|
||||||
regRouter "go.unistack.org/micro-router-register/v3"
|
regRouter "go.unistack.org/micro-router-register/v3"
|
||||||
gserver "go.unistack.org/micro-server-grpc/v3"
|
gserver "go.unistack.org/micro-server-grpc/v3"
|
||||||
gpb "go.unistack.org/micro-tests/server/grpc/gproto"
|
gpb "go.unistack.org/micro-tests/codec/segmentio/proto"
|
||||||
pb "go.unistack.org/micro-tests/server/grpc/proto"
|
|
||||||
"go.unistack.org/micro/v3/broker"
|
|
||||||
"go.unistack.org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"go.unistack.org/micro/v3/errors"
|
"go.unistack.org/micro/v3/errors"
|
||||||
"go.unistack.org/micro/v3/register"
|
mregister "go.unistack.org/micro/v3/register/memory"
|
||||||
"go.unistack.org/micro/v3/router"
|
"go.unistack.org/micro/v3/router"
|
||||||
"go.unistack.org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testServer struct {
|
type testServer struct{}
|
||||||
pb.UnimplementedTestServer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
|
func (g *testServer) Call(ctx context.Context, req *gpb.Request, rsp *gpb.Response) error {
|
||||||
if req.Name == "Error" {
|
if req.Name == "Error" {
|
||||||
return &errors.Error{ID: "id", Code: 99, Detail: "detail"}
|
return &errors.Error{ID: "id", Code: 99, Detail: "detail"}
|
||||||
}
|
}
|
||||||
@ -34,15 +30,13 @@ func (g *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response
|
|||||||
func TestGRPCServer(t *testing.T) {
|
func TestGRPCServer(t *testing.T) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
r := register.NewRegister()
|
r := mregister.NewRegister()
|
||||||
b := broker.NewBroker(broker.Register(r))
|
|
||||||
s := gserver.NewServer(
|
s := gserver.NewServer(
|
||||||
server.Codec("application/grpc+proto", protocodec.NewCodec()),
|
server.Codec("application/grpc+proto", protocodec.NewCodec()),
|
||||||
server.Codec("application/grpc", protocodec.NewCodec()),
|
server.Codec("application/grpc", protocodec.NewCodec()),
|
||||||
server.Address("127.0.0.1:0"),
|
server.Address("127.0.0.1:0"),
|
||||||
server.Register(r),
|
server.Register(r),
|
||||||
server.Name("helloworld"),
|
server.Name("helloworld"),
|
||||||
gserver.Reflection(true),
|
|
||||||
)
|
)
|
||||||
// create router
|
// create router
|
||||||
rtr := regRouter.NewRouter(router.Register(r))
|
rtr := regRouter.NewRouter(router.Register(r))
|
||||||
@ -73,7 +67,6 @@ func TestGRPCServer(t *testing.T) {
|
|||||||
client.Codec("application/grpc", protocodec.NewCodec()),
|
client.Codec("application/grpc", protocodec.NewCodec()),
|
||||||
client.Router(rtr),
|
client.Router(rtr),
|
||||||
client.Register(r),
|
client.Register(r),
|
||||||
client.Broker(b),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
testMethods := []string{
|
testMethods := []string{
|
||||||
@ -81,13 +74,13 @@ func TestGRPCServer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, method := range testMethods {
|
for _, method := range testMethods {
|
||||||
req := c.NewRequest("helloworld", method, &pb.Request{
|
req := c.NewRequest("helloworld", method, &gpb.Request{
|
||||||
Name: "John",
|
Name: "John",
|
||||||
})
|
})
|
||||||
|
|
||||||
rsp := pb.Response{}
|
rsp := &gpb.Response{}
|
||||||
|
|
||||||
err = c.Call(context.TODO(), req, &rsp)
|
err = c.Call(context.TODO(), req, rsp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("method: %s err: %v", method, err)
|
t.Fatalf("method: %s err: %v", method, err)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ package pb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
context "context"
|
context "context"
|
||||||
_ "go.unistack.org/micro-client-http/v3"
|
|
||||||
client "go.unistack.org/micro/v3/client"
|
client "go.unistack.org/micro/v3/client"
|
||||||
server "go.unistack.org/micro/v3/server"
|
server "go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
12
go.mod
12
go.mod
@ -2,6 +2,10 @@ module go.unistack.org/micro-tests
|
|||||||
|
|
||||||
go 1.23.4
|
go 1.23.4
|
||||||
|
|
||||||
|
replace (
|
||||||
|
go.unistack.org/micro-server-grpc/v3 => ../micro-server-grpc
|
||||||
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/jmoiron/sqlx v1.4.0
|
github.com/jmoiron/sqlx v1.4.0
|
||||||
github.com/opentracing/opentracing-go v1.2.0
|
github.com/opentracing/opentracing-go v1.2.0
|
||||||
@ -24,17 +28,17 @@ require (
|
|||||||
go.unistack.org/micro-meter-prometheus/v3 v3.8.17
|
go.unistack.org/micro-meter-prometheus/v3 v3.8.17
|
||||||
go.unistack.org/micro-meter-victoriametrics/v3 v3.8.9
|
go.unistack.org/micro-meter-victoriametrics/v3 v3.8.9
|
||||||
go.unistack.org/micro-proto/v3 v3.4.1
|
go.unistack.org/micro-proto/v3 v3.4.1
|
||||||
go.unistack.org/micro-router-register/v3 v3.9.0
|
go.unistack.org/micro-router-register/v3 v3.10.1
|
||||||
go.unistack.org/micro-server-grpc/v3 v3.10.28
|
go.unistack.org/micro-server-grpc/v3 v3.10.28
|
||||||
go.unistack.org/micro-server-http/v3 v3.11.38
|
go.unistack.org/micro-server-http/v3 v3.11.38
|
||||||
go.unistack.org/micro-server-tcp/v3 v3.10.1
|
go.unistack.org/micro-server-tcp/v3 v3.10.3
|
||||||
go.unistack.org/micro-tracer-opentracing/v3 v3.10.23
|
go.unistack.org/micro-tracer-opentracing/v3 v3.10.23
|
||||||
go.unistack.org/micro-wrapper-recovery/v3 v3.9.0
|
go.unistack.org/micro-wrapper-recovery/v3 v3.9.0
|
||||||
go.unistack.org/micro-wrapper-sql/v3 v3.10.15
|
go.unistack.org/micro-wrapper-sql/v3 v3.10.15
|
||||||
go.unistack.org/micro/v3 v3.11.37
|
go.unistack.org/micro/v3 v3.11.38
|
||||||
golang.org/x/net v0.34.0
|
golang.org/x/net v0.34.0
|
||||||
google.golang.org/grpc v1.69.4
|
google.golang.org/grpc v1.69.4
|
||||||
google.golang.org/protobuf v1.36.2
|
google.golang.org/protobuf v1.36.3
|
||||||
modernc.org/sqlite v1.34.2
|
modernc.org/sqlite v1.34.2
|
||||||
storj.io/drpc v0.0.34
|
storj.io/drpc v0.0.34
|
||||||
)
|
)
|
||||||
|
13
go.sum
13
go.sum
@ -1369,7 +1369,6 @@ github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY
|
|||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
|
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
|
||||||
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
|
||||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
@ -1990,12 +1989,16 @@ go.unistack.org/micro-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqt
|
|||||||
go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo=
|
go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo=
|
||||||
go.unistack.org/micro-router-register/v3 v3.9.0 h1:1TFfUmKwy39zmkqp+a82WvGdpaxJF2+7DY/Gx481jbc=
|
go.unistack.org/micro-router-register/v3 v3.9.0 h1:1TFfUmKwy39zmkqp+a82WvGdpaxJF2+7DY/Gx481jbc=
|
||||||
go.unistack.org/micro-router-register/v3 v3.9.0/go.mod h1:pt4a4hOJn8tniXObwDSAx1cdYR75k35FIp9fiqdWxNc=
|
go.unistack.org/micro-router-register/v3 v3.9.0/go.mod h1:pt4a4hOJn8tniXObwDSAx1cdYR75k35FIp9fiqdWxNc=
|
||||||
|
go.unistack.org/micro-router-register/v3 v3.10.0 h1:nCUjNKfkMttiHt5AU5HPBgLm5GC0OrY8EUlek55MEbg=
|
||||||
|
go.unistack.org/micro-router-register/v3 v3.10.0/go.mod h1:ePlAAdeCtar/YgRTlWxaLB0RnnG3vnfvPEiu4ZMVokQ=
|
||||||
|
go.unistack.org/micro-router-register/v3 v3.10.1 h1:r4pCi1HmV0wRV8W62wyZwTydqCF7R3AYpy3Qca5LDhM=
|
||||||
|
go.unistack.org/micro-router-register/v3 v3.10.1/go.mod h1:ePlAAdeCtar/YgRTlWxaLB0RnnG3vnfvPEiu4ZMVokQ=
|
||||||
go.unistack.org/micro-server-grpc/v3 v3.10.28 h1:mYj3wSlObcMgJbf9rb33c0dLLki/Yd71kcoTgZKsaEU=
|
go.unistack.org/micro-server-grpc/v3 v3.10.28 h1:mYj3wSlObcMgJbf9rb33c0dLLki/Yd71kcoTgZKsaEU=
|
||||||
go.unistack.org/micro-server-grpc/v3 v3.10.28/go.mod h1:PVUmRwHh0ymPq7WMrCemoA0YiDudJaYSm6C/7QvSQdY=
|
go.unistack.org/micro-server-grpc/v3 v3.10.28/go.mod h1:PVUmRwHh0ymPq7WMrCemoA0YiDudJaYSm6C/7QvSQdY=
|
||||||
go.unistack.org/micro-server-http/v3 v3.11.38 h1:gyyd3G1/4xzKUSXTp8lqV7PnsxEntC+R1w5FJsJGOxM=
|
go.unistack.org/micro-server-http/v3 v3.11.38 h1:gyyd3G1/4xzKUSXTp8lqV7PnsxEntC+R1w5FJsJGOxM=
|
||||||
go.unistack.org/micro-server-http/v3 v3.11.38/go.mod h1:k/TUnHfyLNwBEw90vBEJvdC5qX6cnaNvHH1n2rgRmIA=
|
go.unistack.org/micro-server-http/v3 v3.11.38/go.mod h1:k/TUnHfyLNwBEw90vBEJvdC5qX6cnaNvHH1n2rgRmIA=
|
||||||
go.unistack.org/micro-server-tcp/v3 v3.10.1 h1:XU2SGr3IjINIOi+4aisTaT2eXMID7z1KSRw6ds0idkc=
|
go.unistack.org/micro-server-tcp/v3 v3.10.3 h1:LE2/nuk2V4aPISxqaDnLLnDqi1A1wEJw0j2AsGZInjY=
|
||||||
go.unistack.org/micro-server-tcp/v3 v3.10.1/go.mod h1:l7cU1iS2eFfKsR0JCILd/EcEr7etm/2S+gfhOnQ5L/M=
|
go.unistack.org/micro-server-tcp/v3 v3.10.3/go.mod h1:qa9wteSYUfvyvL2/qhz20nuNRHFjRqS7Mhz+ZrFwaKs=
|
||||||
go.unistack.org/micro-tracer-opentracing/v3 v3.10.23 h1:KP0Ryt/VEP/J29DlEQ9zpu9qxJW4qNw85bNjBszcoe4=
|
go.unistack.org/micro-tracer-opentracing/v3 v3.10.23 h1:KP0Ryt/VEP/J29DlEQ9zpu9qxJW4qNw85bNjBszcoe4=
|
||||||
go.unistack.org/micro-tracer-opentracing/v3 v3.10.23/go.mod h1:7Eum62CaU+yJ8S6BtYxz4f8iIDjs73CaVMsrC5kI0GA=
|
go.unistack.org/micro-tracer-opentracing/v3 v3.10.23/go.mod h1:7Eum62CaU+yJ8S6BtYxz4f8iIDjs73CaVMsrC5kI0GA=
|
||||||
go.unistack.org/micro-wrapper-recovery/v3 v3.9.0 h1:naNkcZVpleIsuw3PDJJcPtxGlELLlgSXKb2TWmC5J00=
|
go.unistack.org/micro-wrapper-recovery/v3 v3.9.0 h1:naNkcZVpleIsuw3PDJJcPtxGlELLlgSXKb2TWmC5J00=
|
||||||
@ -2008,6 +2011,8 @@ go.unistack.org/micro/v3 v3.9.2/go.mod h1:7ssIWk+PJXvb2nSl8NUnQRs32JJEId2IDi9Pob
|
|||||||
go.unistack.org/micro/v3 v3.10.66/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
|
go.unistack.org/micro/v3 v3.10.66/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
|
||||||
go.unistack.org/micro/v3 v3.11.37 h1:ZcpnXAYEMcAwmnVb5b7o8/PylGnILxXMHaUlRrPmRI0=
|
go.unistack.org/micro/v3 v3.11.37 h1:ZcpnXAYEMcAwmnVb5b7o8/PylGnILxXMHaUlRrPmRI0=
|
||||||
go.unistack.org/micro/v3 v3.11.37/go.mod h1:POGU5hstnAT9LH70m8FalyQSNi2GfIew71K75JenIZk=
|
go.unistack.org/micro/v3 v3.11.37/go.mod h1:POGU5hstnAT9LH70m8FalyQSNi2GfIew71K75JenIZk=
|
||||||
|
go.unistack.org/micro/v3 v3.11.38 h1:A4a0kCD3PnFyA7tBSlEmXLjw84xiQGOpTVPgYemgkBs=
|
||||||
|
go.unistack.org/micro/v3 v3.11.38/go.mod h1:POGU5hstnAT9LH70m8FalyQSNi2GfIew71K75JenIZk=
|
||||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
@ -2860,6 +2865,8 @@ google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh
|
|||||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||||
google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
|
google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
|
||||||
google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
|
google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
|
||||||
|
google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestWrapper(t *testing.T) {
|
func TestWrapper(t *testing.T) {
|
||||||
|
t.Skip()
|
||||||
m := prometheus.NewMeter() // meter.Labels("test_key", "test_val"))
|
m := prometheus.NewMeter() // meter.Labels("test_key", "test_val"))
|
||||||
_ = m.Init()
|
_ = m.Init()
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestWrapper(t *testing.T) {
|
func TestWrapper(t *testing.T) {
|
||||||
|
t.Skip()
|
||||||
m := victoriametrics.NewMeter() // meter.Labels("test_key", "test_val"))
|
m := victoriametrics.NewMeter() // meter.Labels("test_key", "test_val"))
|
||||||
_ = m.Init()
|
_ = m.Init()
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package pb
|
package pb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
cp "go.unistack.org/micro-codec-proto/v3"
|
cp "go.unistack.org/micro-codec-proto/v3"
|
||||||
@ -20,7 +19,9 @@ func TestMarshalUnmarshal(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
for _, item := range msg1.Items {
|
for _, item := range msg1.Items {
|
||||||
fmt.Printf("item %#+v\n", item)
|
fmt.Printf("item %#+v\n", item)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
pb "go.unistack.org/micro-tests/server/combo/proto"
|
pb "go.unistack.org/micro-tests/server/combo/proto"
|
||||||
"go.unistack.org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"go.unistack.org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"go.unistack.org/micro/v3/register"
|
mregister "go.unistack.org/micro/v3/register/memory"
|
||||||
"go.unistack.org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
"golang.org/x/net/http2/h2c"
|
"golang.org/x/net/http2/h2c"
|
||||||
@ -70,7 +70,7 @@ func (h *Handler) Call(ctx context.Context, req *pb.CallReq, rsp *pb.CallRsp) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestComboServer(t *testing.T) {
|
func TestComboServer(t *testing.T) {
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
h := &Handler{t: t}
|
h := &Handler{t: t}
|
||||||
@ -111,7 +111,7 @@ func TestComboServer(t *testing.T) {
|
|||||||
hs := &http.Server{Handler: h2c.NewHandler(newComboMux(hsrv, gsrv.GRPCServer(), nil), &http2.Server{})}
|
hs := &http.Server{Handler: h2c.NewHandler(newComboMux(hsrv, gsrv.GRPCServer(), nil), &http2.Server{})}
|
||||||
|
|
||||||
// init http server
|
// init http server
|
||||||
if err := hsrv.Init(httpsrv.Server(hs)); err != nil {
|
if err := hsrv.Init(httpsrv.HTTPServer(hs)); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,11 @@ package combo
|
|||||||
|
|
||||||
//go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go_out=paths=source_relative:./proto proto/proto.proto"
|
//go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go_out=paths=source_relative:./proto proto/proto.proto"
|
||||||
|
|
||||||
//go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components='micro|grpc',standalone=true,debug=true,paths=source_relative:./mgpb proto/proto.proto"
|
//go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components='micro',standalone=false,debug=true,paths=source_relative:./proto proto/proto.proto"
|
||||||
|
|
||||||
//go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components='micro|http',standalone=true,debug=true,paths=source_relative:./mhpb proto/proto.proto"
|
//go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components='grpc',standalone=true,debug=true,paths=source_relative:./mgpb proto/proto.proto"
|
||||||
|
|
||||||
|
//go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components='http',standalone=true,debug=true,paths=source_relative:./mhpb proto/proto.proto"
|
||||||
|
|
||||||
//go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components='openapiv3',openapi_file=./apidocs.swagger.yaml,standalone=true,debug=true,paths=source_relative:./proto proto/proto.proto"
|
//go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components='openapiv3',openapi_file=./apidocs.swagger.yaml,standalone=true,debug=true,paths=source_relative:./proto proto/proto.proto"
|
||||||
|
|
||||||
@ -14,8 +16,6 @@ package combo
|
|||||||
////go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go_out=paths=source_relative:./ndpb proto/proto.proto"
|
////go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go_out=paths=source_relative:./ndpb proto/proto.proto"
|
||||||
////go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-drpc_out=json=false,paths=source_relative:./ndpb proto/proto.proto"
|
////go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-drpc_out=json=false,paths=source_relative:./ndpb proto/proto.proto"
|
||||||
|
|
||||||
////go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components='micro|http',standalone=true,debug=true,paths=source_relative:./mhpb proto/proto.proto"
|
|
||||||
|
|
||||||
////go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components='micro|drpc',standalone=true,debug=true,paths=source_relative:./mdpb proto/proto.proto"
|
////go:generate sh -c "protoc -I./proto -I. -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) --go-micro_out=components='micro|drpc',standalone=true,debug=true,paths=source_relative:./mdpb proto/proto.proto"
|
||||||
|
|
||||||
//go:generate sh -c "mkdir -p swagger-ui && cp proto/apidocs.swagger.yaml swagger-ui/swagger.yaml && curl -L https://github.com/swagger-api/swagger-ui/archive/refs/tags/v4.17.0.tar.gz -o v4.17.0.tar.gz && tar -C swagger-ui --strip-components=2 -zxvf v4.17.0.tar.gz swagger-ui-4.17.0/dist && rm -f v4.17.0.tar.gz && sed -i '' 's|https://petstore.swagger.io/v2/swagger.json|./swagger.yaml|g' swagger-ui/index.html swagger-ui/swagger-initializer.js && sed -i '' 's|deepLinking: true,|deepLinking: true, displayOperationId: true, tryItOutEnabled: true,|g' swagger-ui/swagger-initializer.js "
|
//go:generate sh -c "mkdir -p swagger-ui && cp proto/apidocs.swagger.yaml swagger-ui/swagger.yaml && curl -L https://github.com/swagger-api/swagger-ui/archive/refs/tags/v4.17.0.tar.gz -o v4.17.0.tar.gz && tar -C swagger-ui --strip-components=2 -zxvf v4.17.0.tar.gz swagger-ui-4.17.0/dist && rm -f v4.17.0.tar.gz && sed -i '' 's|https://petstore.swagger.io/v2/swagger.json|./swagger.yaml|g' swagger-ui/index.html swagger-ui/swagger-initializer.js && sed -i '' 's|deepLinking: true,|deepLinking: true, displayOperationId: true, tryItOutEnabled: true,|g' swagger-ui/swagger-initializer.js "
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
|
||||||
// protoc-gen-go-micro version: v3.10.4
|
|
||||||
|
|
||||||
package pb
|
|
||||||
|
|
||||||
import (
|
|
||||||
protojson "google.golang.org/protobuf/encoding/protojson"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
marshaler = protojson.MarshalOptions{}
|
|
||||||
)
|
|
||||||
|
|
||||||
func (m *Error) Error() string {
|
|
||||||
buf, _ := marshaler.Marshal(m)
|
|
||||||
return string(buf)
|
|
||||||
}
|
|
@ -37,7 +37,7 @@ func NewTestClient(name string, c client.Client) proto.TestClient {
|
|||||||
|
|
||||||
func (c *testClient) Call(ctx context.Context, req *proto.CallReq, opts ...client.CallOption) (*proto.CallRsp, error) {
|
func (c *testClient) Call(ctx context.Context, req *proto.CallReq, opts ...client.CallOption) (*proto.CallRsp, error) {
|
||||||
errmap := make(map[string]interface{}, 1)
|
errmap := make(map[string]interface{}, 1)
|
||||||
errmap["default"] = &proto.Error{}
|
errmap["default"] = &proto.ErrorRsp{}
|
||||||
opts = append(opts,
|
opts = append(opts,
|
||||||
v31.ErrorMap(errmap),
|
v31.ErrorMap(errmap),
|
||||||
)
|
)
|
||||||
|
@ -22,7 +22,7 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Error'
|
$ref: '#/components/schemas/ErrorRsp'
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
content:
|
content:
|
||||||
@ -41,7 +41,7 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
rsp:
|
rsp:
|
||||||
type: string
|
type: string
|
||||||
Error:
|
ErrorRsp:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
err:
|
err:
|
||||||
|
@ -11,7 +11,7 @@ var (
|
|||||||
marshaler = protojson.MarshalOptions{}
|
marshaler = protojson.MarshalOptions{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *Error) Error() string {
|
func (m *ErrorRsp) Error() string {
|
||||||
buf, _ := marshaler.Marshal(m)
|
buf, _ := marshaler.Marshal(m)
|
||||||
return string(buf)
|
return string(buf)
|
||||||
}
|
}
|
@ -118,7 +118,7 @@ func (x *CallRsp) GetRsp() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
type Error struct {
|
type ErrorRsp struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
@ -126,8 +126,8 @@ type Error struct {
|
|||||||
Err string `protobuf:"bytes,1,opt,name=err,proto3" json:"err,omitempty"`
|
Err string `protobuf:"bytes,1,opt,name=err,proto3" json:"err,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Error) Reset() {
|
func (x *ErrorRsp) Reset() {
|
||||||
*x = Error{}
|
*x = ErrorRsp{}
|
||||||
if protoimpl.UnsafeEnabled {
|
if protoimpl.UnsafeEnabled {
|
||||||
mi := &file_proto_proto_msgTypes[2]
|
mi := &file_proto_proto_msgTypes[2]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
@ -135,13 +135,13 @@ func (x *Error) Reset() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Error) String() string {
|
func (x *ErrorRsp) String() string {
|
||||||
return protoimpl.X.MessageStringOf(x)
|
return protoimpl.X.MessageStringOf(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Error) ProtoMessage() {}
|
func (*ErrorRsp) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *Error) ProtoReflect() protoreflect.Message {
|
func (x *ErrorRsp) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_proto_proto_msgTypes[2]
|
mi := &file_proto_proto_msgTypes[2]
|
||||||
if protoimpl.UnsafeEnabled && x != nil {
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
@ -153,12 +153,12 @@ func (x *Error) ProtoReflect() protoreflect.Message {
|
|||||||
return mi.MessageOf(x)
|
return mi.MessageOf(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: Use Error.ProtoReflect.Descriptor instead.
|
// Deprecated: Use ErrorRsp.ProtoReflect.Descriptor instead.
|
||||||
func (*Error) Descriptor() ([]byte, []int) {
|
func (*ErrorRsp) Descriptor() ([]byte, []int) {
|
||||||
return file_proto_proto_rawDescGZIP(), []int{2}
|
return file_proto_proto_rawDescGZIP(), []int{2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Error) GetErr() string {
|
func (x *ErrorRsp) GetErr() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Err
|
return x.Err
|
||||||
}
|
}
|
||||||
@ -179,20 +179,20 @@ var file_proto_proto_rawDesc = []byte{
|
|||||||
0x1b, 0x0a, 0x07, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65,
|
0x1b, 0x0a, 0x07, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65,
|
||||||
0x71, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x65, 0x71, 0x22, 0x1b, 0x0a, 0x07,
|
0x71, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x65, 0x71, 0x22, 0x1b, 0x0a, 0x07,
|
||||||
0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x73, 0x70, 0x18, 0x01,
|
0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x73, 0x70, 0x18, 0x01,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x73, 0x70, 0x22, 0x19, 0x0a, 0x05, 0x45, 0x72, 0x72,
|
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x73, 0x70, 0x22, 0x1c, 0x0a, 0x08, 0x45, 0x72, 0x72,
|
||||||
0x6f, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x72, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x6f, 0x72, 0x52, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x72, 0x72, 0x18, 0x01, 0x20, 0x01,
|
||||||
0x03, 0x65, 0x72, 0x72, 0x32, 0x77, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x12, 0x6f, 0x0a, 0x04,
|
0x28, 0x09, 0x52, 0x03, 0x65, 0x72, 0x72, 0x32, 0x7a, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x12,
|
||||||
0x43, 0x61, 0x6c, 0x6c, 0x12, 0x16, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x70,
|
0x72, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x16, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x76,
|
||||||
0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x74,
|
0x31, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x1a,
|
||||||
0x65, 0x73, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x61, 0x6c,
|
0x16, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
|
||||||
0x6c, 0x52, 0x73, 0x70, 0x22, 0x37, 0xaa, 0x84, 0x9e, 0x03, 0x22, 0x2a, 0x04, 0x43, 0x61, 0x6c,
|
0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x22, 0x3a, 0xaa, 0x84, 0x9e, 0x03, 0x25, 0x2a, 0x04,
|
||||||
0x6c, 0x42, 0x1a, 0x0a, 0x18, 0x12, 0x16, 0x0a, 0x14, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x76,
|
0x43, 0x61, 0x6c, 0x6c, 0x42, 0x1d, 0x0a, 0x1b, 0x12, 0x19, 0x0a, 0x17, 0x2e, 0x74, 0x65, 0x73,
|
||||||
0x31, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0xb2, 0xea, 0xff,
|
0x74, 0x2e, 0x76, 0x31, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72,
|
||||||
0xf9, 0x01, 0x0a, 0x22, 0x05, 0x2f, 0x43, 0x61, 0x6c, 0x6c, 0x3a, 0x01, 0x2a, 0x42, 0x33, 0x5a,
|
0x52, 0x73, 0x70, 0xb2, 0xea, 0xff, 0xf9, 0x01, 0x0a, 0x22, 0x05, 0x2f, 0x43, 0x61, 0x6c, 0x6c,
|
||||||
0x31, 0x67, 0x6f, 0x2e, 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2e, 0x6f, 0x72, 0x67,
|
0x3a, 0x01, 0x2a, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x6f, 0x2e, 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61,
|
||||||
0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x73, 0x65, 0x72,
|
0x63, 0x6b, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x74, 0x65, 0x73,
|
||||||
0x76, 0x65, 0x72, 0x2f, 0x63, 0x6f, 0x6d, 0x62, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b,
|
0x74, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x63, 0x6f, 0x6d, 0x62, 0x6f, 0x2f,
|
||||||
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -211,7 +211,7 @@ var file_proto_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
|||||||
var file_proto_proto_goTypes = []interface{}{
|
var file_proto_proto_goTypes = []interface{}{
|
||||||
(*CallReq)(nil), // 0: test.v1.proto.CallReq
|
(*CallReq)(nil), // 0: test.v1.proto.CallReq
|
||||||
(*CallRsp)(nil), // 1: test.v1.proto.CallRsp
|
(*CallRsp)(nil), // 1: test.v1.proto.CallRsp
|
||||||
(*Error)(nil), // 2: test.v1.proto.Error
|
(*ErrorRsp)(nil), // 2: test.v1.proto.ErrorRsp
|
||||||
}
|
}
|
||||||
var file_proto_proto_depIdxs = []int32{
|
var file_proto_proto_depIdxs = []int32{
|
||||||
0, // 0: test.v1.proto.Test.Call:input_type -> test.v1.proto.CallReq
|
0, // 0: test.v1.proto.Test.Call:input_type -> test.v1.proto.CallReq
|
||||||
@ -254,7 +254,7 @@ func file_proto_proto_init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_proto_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
file_proto_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||||
switch v := v.(*Error); i {
|
switch v := v.(*ErrorRsp); i {
|
||||||
case 0:
|
case 0:
|
||||||
return &v.state
|
return &v.state
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -16,7 +16,7 @@ service Test {
|
|||||||
responses: {
|
responses: {
|
||||||
default: {
|
default: {
|
||||||
reference: {
|
reference: {
|
||||||
_ref: ".test.v1.proto.Error";
|
_ref: ".test.v1.proto.ErrorRsp";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -33,6 +33,6 @@ message CallRsp {
|
|||||||
string rsp = 1;
|
string rsp = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
message Error {
|
message ErrorRsp {
|
||||||
string err = 1;
|
string err = 1;
|
||||||
};
|
};
|
||||||
|
24
server/combo/proto/proto_micro.pb.go
Normal file
24
server/combo/proto/proto_micro.pb.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-micro v3.10.4
|
||||||
|
// - protoc v5.29.2
|
||||||
|
// source: proto.proto
|
||||||
|
|
||||||
|
package pb
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
client "go.unistack.org/micro/v3/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
TestName = "Test"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TestClient interface {
|
||||||
|
Call(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestServer interface {
|
||||||
|
Call(ctx context.Context, req *CallReq, rsp *CallRsp) error
|
||||||
|
}
|
@ -22,7 +22,7 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Error'
|
$ref: '#/components/schemas/ErrorRsp'
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
content:
|
content:
|
||||||
@ -41,7 +41,7 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
rsp:
|
rsp:
|
||||||
type: string
|
type: string
|
||||||
Error:
|
ErrorRsp:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
err:
|
err:
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
//go:generate go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
//go:generate go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
||||||
//go:generate sh -c "protoc -I./proto -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --go-micro_out=components='micro|grpc',debug=true,standalone=true,paths=source_relative:./gproto proto/test.proto"
|
//go:generate sh -c "protoc -I./proto -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto proto/test.proto"
|
||||||
|
//go:generate sh -c "protoc -I./proto -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --go-micro_out=components='micro',debug=true,standalone=true,paths=source_relative:./gproto proto/test.proto"
|
||||||
|
//go:generate sh -c "protoc -I./proto -I$(go list -f '{{ .Dir }}' -m go.unistack.org/micro-proto/v3) -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --go-micro_out=components='grpc',debug=true,standalone=true,paths=source_relative:./gproto proto/test.proto"
|
||||||
|
@ -17,7 +17,7 @@ type testClient struct {
|
|||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTestClient(name string, c client.Client) proto.TestClient {
|
func NewTestClient(name string, c client.Client) TestClient {
|
||||||
return &testClient{c: c, name: name}
|
return &testClient{c: c, name: name}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ func (c *testClient) Call(ctx context.Context, req *proto.Request, opts ...clien
|
|||||||
return rsp, nil
|
return rsp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *testClient) StreamCall(ctx context.Context, opts ...client.CallOption) (proto.Test_StreamCallClient, error) {
|
func (c *testClient) StreamCall(ctx context.Context, opts ...client.CallOption) (Test_StreamCallClient, error) {
|
||||||
stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "Test.StreamCall", &proto.Request{}), opts...)
|
stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "Test.StreamCall", &proto.Request{}), opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -91,7 +91,7 @@ func (s *testClientStreamCall) Recv() (*proto.Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type testServer struct {
|
type testServer struct {
|
||||||
proto.TestServer
|
TestServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *testServer) Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error {
|
func (h *testServer) Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error {
|
||||||
@ -141,7 +141,7 @@ func (s *testStreamCallStream) Recv() (*proto.Request, error) {
|
|||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterTestServer(s server.Server, sh proto.TestServer, opts ...server.HandlerOption) error {
|
func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOption) error {
|
||||||
type test interface {
|
type test interface {
|
||||||
Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error
|
Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error
|
||||||
StreamCall(ctx context.Context, stream server.Stream) error
|
StreamCall(ctx context.Context, stream server.Stream) error
|
||||||
|
@ -18,11 +18,10 @@ import (
|
|||||||
pb "go.unistack.org/micro-tests/server/grpc/proto"
|
pb "go.unistack.org/micro-tests/server/grpc/proto"
|
||||||
"go.unistack.org/micro/v3/broker"
|
"go.unistack.org/micro/v3/broker"
|
||||||
"go.unistack.org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"go.unistack.org/micro/v3/codec"
|
|
||||||
"go.unistack.org/micro/v3/errors"
|
"go.unistack.org/micro/v3/errors"
|
||||||
"go.unistack.org/micro/v3/logger"
|
"go.unistack.org/micro/v3/logger"
|
||||||
"go.unistack.org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"go.unistack.org/micro/v3/register"
|
mregister "go.unistack.org/micro/v3/register/memory"
|
||||||
"go.unistack.org/micro/v3/router"
|
"go.unistack.org/micro/v3/router"
|
||||||
"go.unistack.org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -39,8 +38,8 @@ type testnServer struct {
|
|||||||
pb.UnimplementedTestServer
|
pb.UnimplementedTestServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServerHandlerWrapper() server.HandlerWrapper {
|
func NewServerHandlerWrapper() server.HookHandler {
|
||||||
return func(fn server.HandlerFunc) server.HandlerFunc {
|
return func(fn server.FuncHandler) server.FuncHandler {
|
||||||
return func(ctx context.Context, req server.Request, rsp interface{}) error {
|
return func(ctx context.Context, req server.Request, rsp interface{}) error {
|
||||||
// fmt.Printf("wrap ctx: %#+v req: %#+v\n", ctx, req)
|
// fmt.Printf("wrap ctx: %#+v req: %#+v\n", ctx, req)
|
||||||
return fn(ctx, req, rsp)
|
return fn(ctx, req, rsp)
|
||||||
@ -62,6 +61,10 @@ func (g *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *testServer) StreamCall(ctx context.Context, stream gpb.Test_StreamCallStream) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (g *testnServer) Call(ctx context.Context, req *pb.Request) (*pb.Response, error) {
|
func (g *testnServer) Call(ctx context.Context, req *pb.Request) (*pb.Response, error) {
|
||||||
_, ok := gmetadata.FromIncomingContext(ctx)
|
_, ok := gmetadata.FromIncomingContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -81,11 +84,10 @@ func (g *testnServer) Call(ctx context.Context, req *pb.Request) (*pb.Response,
|
|||||||
|
|
||||||
func TestGRPCServer(t *testing.T) {
|
func TestGRPCServer(t *testing.T) {
|
||||||
var err error
|
var err error
|
||||||
codec.DefaultMaxMsgSize = 8 * 1024 * 1024
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
_ = logger.DefaultLogger.Init(logger.WithLevel(logger.ErrorLevel))
|
_ = logger.DefaultLogger.Init(logger.WithLevel(logger.ErrorLevel))
|
||||||
r := register.NewRegister()
|
r := mregister.NewRegister()
|
||||||
b := broker.NewBroker(broker.Register(r))
|
b := broker.NewBroker(broker.Register(r))
|
||||||
s := gserver.NewServer(
|
s := gserver.NewServer(
|
||||||
server.Codec("application/grpc+proto", protocodec.NewCodec()),
|
server.Codec("application/grpc+proto", protocodec.NewCodec()),
|
||||||
@ -93,8 +95,8 @@ func TestGRPCServer(t *testing.T) {
|
|||||||
server.Address("127.0.0.1:0"),
|
server.Address("127.0.0.1:0"),
|
||||||
server.Register(r),
|
server.Register(r),
|
||||||
server.Name("helloworld"),
|
server.Name("helloworld"),
|
||||||
gserver.Reflection(true),
|
// gserver.Reflection(true),
|
||||||
server.WrapHandler(NewServerHandlerWrapper()),
|
server.Hooks(server.HookHandler(NewServerHandlerWrapper())),
|
||||||
)
|
)
|
||||||
// create router
|
// create router
|
||||||
rtr := regRouter.NewRouter(router.Register(r))
|
rtr := regRouter.NewRouter(router.Register(r))
|
||||||
|
@ -3,6 +3,7 @@ package http_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -25,7 +26,7 @@ import (
|
|||||||
pb "go.unistack.org/micro-tests/server/http/proto"
|
pb "go.unistack.org/micro-tests/server/http/proto"
|
||||||
"go.unistack.org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"go.unistack.org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"go.unistack.org/micro/v3/register"
|
mregister "go.unistack.org/micro/v3/register/memory"
|
||||||
"go.unistack.org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
|
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
|
||||||
)
|
)
|
||||||
@ -82,7 +83,7 @@ func upload(client *http.Client, url string, values map[string]io.Reader) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMultipart(t *testing.T) {
|
func TestMultipart(t *testing.T) {
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// create server
|
// create server
|
||||||
@ -133,27 +134,28 @@ func TestMultipart(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServerHandlerWrapper(t *testing.T) server.HandlerWrapper {
|
func NewServerHandlerWrapper(t *testing.T) server.HookHandler {
|
||||||
return func(fn server.HandlerFunc) server.HandlerFunc {
|
return func(fn server.FuncHandler) server.FuncHandler {
|
||||||
return func(ctx context.Context, req server.Request, rsp interface{}) error {
|
return func(ctx context.Context, req server.Request, rsp interface{}) error {
|
||||||
md, ok := metadata.FromIncomingContext(ctx)
|
// return fn(ctx, req, rsp)
|
||||||
|
imd, ok := metadata.FromIncomingContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("metadata empty")
|
return errors.New("missing metadata")
|
||||||
}
|
}
|
||||||
if v, ok := md.Get("Authorization"); ok && v == "test" {
|
nmd, ok := metadata.FromOutgoingContext(ctx)
|
||||||
nmd := metadata.New(1)
|
if !ok {
|
||||||
|
return errors.New("missing metadata")
|
||||||
|
}
|
||||||
|
if v, ok := imd.Get("Authorization"); ok && v == "test" {
|
||||||
nmd.Set("my-key", "my-val")
|
nmd.Set("my-key", "my-val")
|
||||||
nmd.Set("Content-Type", "text/xml")
|
nmd.Set("Content-Type", "text/xml")
|
||||||
metadata.SetOutgoingContext(ctx, nmd)
|
|
||||||
httpsrv.SetRspCode(ctx, http.StatusUnauthorized)
|
httpsrv.SetRspCode(ctx, http.StatusUnauthorized)
|
||||||
return httpsrv.SetError(&pb.CallRsp{Rsp: "name_my_name"})
|
return httpsrv.SetError(&pb.CallRsp{Rsp: "name_my_name"})
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := md.Get("Test-Content-Type"); ok && v != "" {
|
if v, ok := imd.Get("Test-Content-Type"); ok && v != "" {
|
||||||
nmd := metadata.New(1)
|
|
||||||
nmd.Set("my-key", "my-val")
|
nmd.Set("my-key", "my-val")
|
||||||
nmd.Set("Content-Type", v)
|
nmd.Set("Content-Type", v)
|
||||||
metadata.SetOutgoingContext(ctx, nmd)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fn(ctx, req, rsp)
|
return fn(ctx, req, rsp)
|
||||||
@ -196,20 +198,29 @@ func (h *Handler) Call(ctx context.Context, req *pb.CallReq, rsp *pb.CallRsp) er
|
|||||||
if !ok {
|
if !ok {
|
||||||
h.t.Fatalf("context without metadata")
|
h.t.Fatalf("context without metadata")
|
||||||
}
|
}
|
||||||
|
omd, ok := metadata.FromOutgoingContext(ctx)
|
||||||
|
if !ok {
|
||||||
|
h.t.Fatalf("context without metadata")
|
||||||
|
}
|
||||||
if _, ok := md.Get("User-Agent"); !ok {
|
if _, ok := md.Get("User-Agent"); !ok {
|
||||||
h.t.Fatalf("context metadata does not have User-Agent header")
|
h.t.Fatalf("context metadata does not have User-Agent header")
|
||||||
}
|
}
|
||||||
if req.Name != "my_name" {
|
if req.Name != "my_name" {
|
||||||
h.t.Fatalf("invalid req received: %#+v", req)
|
h.t.Fatalf("invalid req received: %#+v", req)
|
||||||
}
|
}
|
||||||
if req.Clientid != "1234567890" {
|
if v, ok := md.Get("Authorization"); ok && v == "test" {
|
||||||
h.t.Fatalf("invalid req recevided %#+v", req)
|
rsp.Rsp = "name_my_name"
|
||||||
|
httpsrv.SetRspCode(ctx, http.StatusUnauthorized)
|
||||||
|
omd.Set("my-key", "my-val")
|
||||||
|
omd.Set("Content-Type", "text/xml")
|
||||||
|
return httpsrv.SetError(&pb.CallRsp{Rsp: "name_my_name"})
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp.Rsp = "name_my_name"
|
rsp.Rsp = "name_my_name"
|
||||||
httpsrv.SetRspCode(ctx, http.StatusCreated)
|
httpsrv.SetRspCode(ctx, http.StatusCreated)
|
||||||
md = metadata.New(1)
|
if omd, ok := metadata.FromOutgoingContext(ctx); ok {
|
||||||
md.Set("my-key", "my-val")
|
omd.Set("my-key", "my-val")
|
||||||
metadata.SetOutgoingContext(ctx, md)
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +236,7 @@ func (h *Handler) CallError(ctx context.Context, req *pb.CallReq1, rsp *pb.CallR
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNativeFormUrlencoded(t *testing.T) {
|
func TestNativeFormUrlencoded(t *testing.T) {
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// create server
|
// create server
|
||||||
@ -340,7 +351,7 @@ func TestNativeFormUrlencoded(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNativeClientServer(t *testing.T) {
|
func TestNativeClientServer(t *testing.T) {
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
var mwfOk bool
|
var mwfOk bool
|
||||||
@ -361,7 +372,7 @@ func TestNativeClientServer(t *testing.T) {
|
|||||||
server.Codec("application/json", jsonpbcodec.NewCodec()),
|
server.Codec("application/json", jsonpbcodec.NewCodec()),
|
||||||
server.Codec("application/x-www-form-urlencoded", urlencodecodec.NewCodec()),
|
server.Codec("application/x-www-form-urlencoded", urlencodecodec.NewCodec()),
|
||||||
httpsrv.Middleware(mwf),
|
httpsrv.Middleware(mwf),
|
||||||
server.WrapHandler(NewServerHandlerWrapper(t)),
|
server.Hooks(server.HookHandler(NewServerHandlerWrapper(t))),
|
||||||
)
|
)
|
||||||
|
|
||||||
h := &Handler{t: t}
|
h := &Handler{t: t}
|
||||||
@ -493,7 +504,7 @@ func TestNativeClientServer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNativeServer(t *testing.T) {
|
func TestNativeServer(t *testing.T) {
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// create server
|
// create server
|
||||||
@ -504,7 +515,7 @@ func TestNativeServer(t *testing.T) {
|
|||||||
server.Codec("text/xml", xmlcodec.NewCodec()),
|
server.Codec("text/xml", xmlcodec.NewCodec()),
|
||||||
server.Codec("application/json", jsoncodec.NewCodec()),
|
server.Codec("application/json", jsoncodec.NewCodec()),
|
||||||
server.Codec("application/x-www-form-urlencoded", urlencodecodec.NewCodec()),
|
server.Codec("application/x-www-form-urlencoded", urlencodecodec.NewCodec()),
|
||||||
server.WrapHandler(NewServerHandlerWrapper(t)),
|
// server.Hooks(server.HookHandler(NewServerHandlerWrapper(t))),
|
||||||
)
|
)
|
||||||
|
|
||||||
h := &Handler{t: t}
|
h := &Handler{t: t}
|
||||||
@ -522,7 +533,7 @@ func TestNativeServer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start server
|
// start server
|
||||||
if err := srv.Start(); err != nil {
|
if err = srv.Start(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,7 +557,7 @@ func TestNativeServer(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
req.Header.Set("Authorization", "test")
|
req.Header.Set("Authorization", "test")
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "text/xml")
|
||||||
rsp, err := http.DefaultClient.Do(req)
|
rsp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -598,7 +609,7 @@ func TestNativeServer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
fn(rr, rq)
|
fn(rr, rq)
|
||||||
if rr.Code != http.StatusBadRequest {
|
if rr.Code != http.StatusBadRequest {
|
||||||
t.Fatalf("invalid status received: %s\n", rr.Body.String())
|
t.Fatalf("invalid status received: %#+v %s\n", rr.Header(), rr.Body.String())
|
||||||
}
|
}
|
||||||
if s := rr.Body.String(); s != `{"msg":"my_error_test"}` {
|
if s := rr.Body.String(); s != `{"msg":"my_error_test"}` {
|
||||||
t.Fatalf("Expected response %s, got %s", `{"msg":"my_error_test"}`, s)
|
t.Fatalf("Expected response %s, got %s", `{"msg":"my_error_test"}`, s)
|
||||||
@ -657,7 +668,7 @@ func TestNativeServer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPHandler(t *testing.T) {
|
func TestHTTPHandler(t *testing.T) {
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// create server
|
// create server
|
||||||
@ -736,7 +747,7 @@ func (h *handlerSwapper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPServer(t *testing.T) {
|
func TestHTTPServer(t *testing.T) {
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// create server mux
|
// create server mux
|
||||||
@ -754,7 +765,7 @@ func TestHTTPServer(t *testing.T) {
|
|||||||
srv := httpsrv.NewServer(
|
srv := httpsrv.NewServer(
|
||||||
server.Address("127.0.0.1:0"),
|
server.Address("127.0.0.1:0"),
|
||||||
server.Register(reg),
|
server.Register(reg),
|
||||||
httpsrv.Server(&http.Server{Handler: h}),
|
httpsrv.HTTPServer(&http.Server{Handler: h}),
|
||||||
server.Codec("application/json", jsoncodec.NewCodec()),
|
server.Codec("application/json", jsoncodec.NewCodec()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -234,8 +234,8 @@ func (h *testServer) Call(ctx context.Context, req *CallReq, rsp *CallRsp) error
|
|||||||
ctx, cancel = context.WithTimeout(ctx, td)
|
ctx, cancel = context.WithTimeout(ctx, td)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
v3.FillRequest(ctx, req,
|
v3.FillRequest(ctx, req,
|
||||||
v3.Cookie("Csrftoken", "true"),
|
|
||||||
v3.Header("Clientid", "true"),
|
v3.Header("Clientid", "true"),
|
||||||
|
v3.Cookie("Csrftoken", "true"),
|
||||||
)
|
)
|
||||||
return h.TestServer.Call(ctx, req, rsp)
|
return h.TestServer.Call(ctx, req, rsp)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
tcp "go.unistack.org/micro-server-tcp/v3"
|
tcp "go.unistack.org/micro-server-tcp/v3"
|
||||||
"go.unistack.org/micro/v3/broker"
|
"go.unistack.org/micro/v3/broker"
|
||||||
"go.unistack.org/micro/v3/register"
|
mregister "go.unistack.org/micro/v3/register/memory"
|
||||||
"go.unistack.org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ type testHandler struct {
|
|||||||
func TestTCPServer(t *testing.T) {
|
func TestTCPServer(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
if err := reg.Init(); err != nil {
|
if err := reg.Init(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"go.unistack.org/micro/v3/broker"
|
"go.unistack.org/micro/v3/broker"
|
||||||
"go.unistack.org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"go.unistack.org/micro/v3/errors"
|
"go.unistack.org/micro/v3/errors"
|
||||||
"go.unistack.org/micro/v3/register"
|
mregister "go.unistack.org/micro/v3/register/memory"
|
||||||
"go.unistack.org/micro/v3/router"
|
"go.unistack.org/micro/v3/router"
|
||||||
"go.unistack.org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
mt "go.unistack.org/micro/v3/tracer"
|
mt "go.unistack.org/micro/v3/tracer"
|
||||||
@ -104,7 +104,7 @@ func TestClient(t *testing.T) {
|
|||||||
defer cl.Close()
|
defer cl.Close()
|
||||||
opentracing.SetGlobalTracer(tr)
|
opentracing.SetGlobalTracer(tr)
|
||||||
|
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
brk := broker.NewBroker(broker.Register(reg))
|
brk := broker.NewBroker(broker.Register(reg))
|
||||||
|
|
||||||
serverName := "service"
|
serverName := "service"
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2018-2021 Matous Dzivjak <matousdzivjak@gmail.com>
|
|
||||||
Copyright (c) 2021 Unistack LLC <v.tolstov@unistack.org>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
@ -1,42 +0,0 @@
|
|||||||
package id
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
mid "go.unistack.org/micro/v3/util/id"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHasNoCollisions(t *testing.T) {
|
|
||||||
tries := 100_000
|
|
||||||
used := make(map[string]bool, tries)
|
|
||||||
for i := 0; i < tries; i++ {
|
|
||||||
id := mid.Must()
|
|
||||||
require.False(t, used[id], "shouldn't return colliding IDs")
|
|
||||||
used[id] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFlatDistribution(t *testing.T) {
|
|
||||||
tries := 100_000
|
|
||||||
alphabet := "abcdefghij"
|
|
||||||
size := 10
|
|
||||||
chars := make(map[rune]int)
|
|
||||||
for i := 0; i < tries; i++ {
|
|
||||||
id := mid.Must(mid.Alphabet(alphabet), mid.Size(size))
|
|
||||||
for _, r := range id {
|
|
||||||
chars[r]++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, count := range chars {
|
|
||||||
require.InEpsilon(t, size*tries/len(alphabet), count, .01, "should have flat distribution")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Benchmark id generator
|
|
||||||
func BenchmarkNanoid(b *testing.B) {
|
|
||||||
for n := 0; n < b.N; n++ {
|
|
||||||
_, _ = mid.New()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
package id_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
id "go.unistack.org/micro/v3/util/id"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestGenerate(t *testing.T) {
|
|
||||||
t.Run("short alphabet", func(t *testing.T) {
|
|
||||||
alphabet := ""
|
|
||||||
_, err := id.New(id.Alphabet(alphabet), id.Size(32))
|
|
||||||
assert.Error(t, err, "should return error if the alphabet is too small")
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("long alphabet", func(t *testing.T) {
|
|
||||||
alphabet := strings.Repeat("a", 256)
|
|
||||||
_, err := id.New(id.Alphabet(alphabet), id.Size(32))
|
|
||||||
assert.Error(t, err, "should return error if the alphabet is too long")
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("negative ID length", func(t *testing.T) {
|
|
||||||
_, err := id.New(id.Alphabet("abcdef"), id.Size(-1))
|
|
||||||
assert.Error(t, err, "should return error if the requested ID length is invalid")
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("happy path", func(t *testing.T) {
|
|
||||||
alphabet := "abcdef"
|
|
||||||
id, err := id.New(id.Alphabet(alphabet), id.Size(6))
|
|
||||||
assert.NoError(t, err, "shouldn't return error")
|
|
||||||
assert.Len(t, id, 6, "should return ID of requested length")
|
|
||||||
for _, r := range id {
|
|
||||||
assert.True(t, strings.ContainsRune(alphabet, r), "should use given alphabet")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("works with unicode", func(t *testing.T) {
|
|
||||||
alphabet := "🚀💩🦄🤖"
|
|
||||||
id, err := id.New(id.Alphabet(alphabet), id.Size(6))
|
|
||||||
assert.NoError(t, err, "shouldn't return error")
|
|
||||||
assert.Equal(t, utf8.RuneCountInString(id), 6, "should return ID of requested length")
|
|
||||||
for _, r := range id {
|
|
||||||
assert.True(t, strings.ContainsRune(alphabet, r), "should use given alphabet")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNew(t *testing.T) {
|
|
||||||
t.Run("negative ID length", func(t *testing.T) {
|
|
||||||
_, err := id.New(id.Size(-1))
|
|
||||||
assert.Error(t, err, "should return error if the requested ID length is invalid")
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("happy path", func(t *testing.T) {
|
|
||||||
nid, err := id.New()
|
|
||||||
assert.NoError(t, err, "shouldn't return error")
|
|
||||||
assert.Len(t, nid, id.DefaultSize, "should return ID of default length")
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("custom length", func(t *testing.T) {
|
|
||||||
id, err := id.New(id.Size(6))
|
|
||||||
assert.NoError(t, err, "shouldn't return error")
|
|
||||||
assert.Len(t, id, 6, "should return ID of requested length")
|
|
||||||
})
|
|
||||||
}
|
|
@ -10,10 +10,9 @@ import (
|
|||||||
rrouter "go.unistack.org/micro-router-register/v3"
|
rrouter "go.unistack.org/micro-router-register/v3"
|
||||||
srv "go.unistack.org/micro-server-grpc/v3"
|
srv "go.unistack.org/micro-server-grpc/v3"
|
||||||
recwrapper "go.unistack.org/micro-wrapper-recovery/v3"
|
recwrapper "go.unistack.org/micro-wrapper-recovery/v3"
|
||||||
"go.unistack.org/micro/v3/broker"
|
|
||||||
"go.unistack.org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"go.unistack.org/micro/v3/errors"
|
"go.unistack.org/micro/v3/errors"
|
||||||
"go.unistack.org/micro/v3/register"
|
mregister "go.unistack.org/micro/v3/register/memory"
|
||||||
"go.unistack.org/micro/v3/router"
|
"go.unistack.org/micro/v3/router"
|
||||||
"go.unistack.org/micro/v3/server"
|
"go.unistack.org/micro/v3/server"
|
||||||
)
|
)
|
||||||
@ -38,8 +37,7 @@ func (t *testHandler) Method(ctx context.Context, req *TestRequest, rsp *TestRes
|
|||||||
|
|
||||||
func TestRecovery(t *testing.T) {
|
func TestRecovery(t *testing.T) {
|
||||||
// setup
|
// setup
|
||||||
reg := register.NewRegister()
|
reg := mregister.NewRegister()
|
||||||
brk := broker.NewBroker(broker.Register(reg))
|
|
||||||
|
|
||||||
name := "test"
|
name := "test"
|
||||||
id := "id-1234567890"
|
id := "id-1234567890"
|
||||||
@ -63,9 +61,8 @@ func TestRecovery(t *testing.T) {
|
|||||||
server.Version(version),
|
server.Version(version),
|
||||||
server.ID(id),
|
server.ID(id),
|
||||||
server.Register(reg),
|
server.Register(reg),
|
||||||
server.Broker(brk),
|
server.Hooks(
|
||||||
server.WrapHandler(
|
server.HookHandler(recwrapper.NewHook(recwrapper.ServerHandlerFunc(rfn)).ServerHandler),
|
||||||
recwrapper.NewServerHandlerWrapper(recwrapper.ServerHandlerFn(rfn)),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ func initJaeger(service string) (opentracing.Tracer, io.Closer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSqliteWrapper(t *testing.T) {
|
func TestSqliteWrapper(t *testing.T) {
|
||||||
|
t.Skip()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
wrapper.DefaultMeterStatsInterval = 100 * time.Millisecond
|
wrapper.DefaultMeterStatsInterval = 100 * time.Millisecond
|
||||||
meter.DefaultMeter = vmeter.NewMeter()
|
meter.DefaultMeter = vmeter.NewMeter()
|
||||||
@ -77,8 +78,6 @@ func TestSqliteWrapper(t *testing.T) {
|
|||||||
sql.Register("micro-wrapper-sql", wrapper.NewWrapper(&sqlite.Driver{},
|
sql.Register("micro-wrapper-sql", wrapper.NewWrapper(&sqlite.Driver{},
|
||||||
wrapper.DatabaseHost("localhost"),
|
wrapper.DatabaseHost("localhost"),
|
||||||
wrapper.DatabaseName("memory"),
|
wrapper.DatabaseName("memory"),
|
||||||
wrapper.LoggerLevel(logger.DebugLevel),
|
|
||||||
wrapper.LoggerEnabled(true),
|
|
||||||
))
|
))
|
||||||
wdb, err := sql.Open("micro-wrapper-sql", ":memory:")
|
wdb, err := sql.Open("micro-wrapper-sql", ":memory:")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user