@@ -24,10 +24,7 @@ import (
|
||||
meterhandler "go.unistack.org/micro-server-http/v3/handler/meter"
|
||||
pb "go.unistack.org/micro-tests/server/http/proto"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
lwrapper "go.unistack.org/micro/v3/logger/wrapper"
|
||||
"go.unistack.org/micro/v3/metadata"
|
||||
mwrapper "go.unistack.org/micro/v3/meter/wrapper"
|
||||
"go.unistack.org/micro/v3/register"
|
||||
"go.unistack.org/micro/v3/server"
|
||||
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
|
||||
@@ -363,8 +360,6 @@ func TestNativeClientServer(t *testing.T) {
|
||||
server.Register(reg),
|
||||
server.Codec("application/json", jsonpbcodec.NewCodec()),
|
||||
server.Codec("application/x-www-form-urlencoded", urlencodecodec.NewCodec()),
|
||||
server.WrapHandler(mwrapper.NewHandlerWrapper(mwrapper.Meter(m))),
|
||||
server.WrapHandler(lwrapper.NewServerHandlerWrapper(lwrapper.WithEnabled(false), lwrapper.WithLevel(logger.ErrorLevel))),
|
||||
httpsrv.Middleware(mwf),
|
||||
server.WrapHandler(NewServerHandlerWrapper(t)),
|
||||
)
|
||||
|
17
server/http/proto/micro_errors.pb.go
Normal file
17
server/http/proto/micro_errors.pb.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// 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)
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.21.12
|
||||
// protoc v5.28.3
|
||||
// source: test.proto
|
||||
|
||||
package pb
|
||||
|
@@ -1,31 +1,19 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-micro v3.10.2
|
||||
// - protoc v3.21.12
|
||||
// - protoc-gen-go-micro v3.10.4
|
||||
// - protoc v5.28.3
|
||||
// source: test.proto
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
v3 "go.unistack.org/micro-server-http/v3"
|
||||
client "go.unistack.org/micro/v3/client"
|
||||
)
|
||||
|
||||
var (
|
||||
TestDoubleName = "TestDouble"
|
||||
)
|
||||
var (
|
||||
TestDoubleServerEndpoints = []v3.EndpointMetadata{
|
||||
{
|
||||
Name: "TestDouble.CallDouble",
|
||||
Path: "/v1/testdouble/call/name/{name}",
|
||||
Method: "POST",
|
||||
Body: "*",
|
||||
Stream: false,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
type TestDoubleClient interface {
|
||||
CallDouble(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error)
|
||||
@@ -38,38 +26,6 @@ type TestDoubleServer interface {
|
||||
var (
|
||||
TestName = "Test"
|
||||
)
|
||||
var (
|
||||
TestServerEndpoints = []v3.EndpointMetadata{
|
||||
{
|
||||
Name: "Test.CallRepeatedString",
|
||||
Path: "/v1/test/call_repeated_string",
|
||||
Method: "POST",
|
||||
Body: "*",
|
||||
Stream: false,
|
||||
},
|
||||
{
|
||||
Name: "Test.CallRepeatedInt64",
|
||||
Path: "/v1/test/call_repeated_int64",
|
||||
Method: "POST",
|
||||
Body: "*",
|
||||
Stream: false,
|
||||
},
|
||||
{
|
||||
Name: "Test.Call",
|
||||
Path: "/v1/test/call/{name}",
|
||||
Method: "POST",
|
||||
Body: "*",
|
||||
Stream: false,
|
||||
},
|
||||
{
|
||||
Name: "Test.CallError",
|
||||
Path: "/v1/test/callerror/{name}",
|
||||
Method: "POST",
|
||||
Body: "*",
|
||||
Stream: false,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
type TestClient interface {
|
||||
CallRepeatedString(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error)
|
||||
|
@@ -1,19 +1,31 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// protoc-gen-go-micro version: v3.10.2
|
||||
// protoc-gen-go-micro version: v3.10.4
|
||||
// source: test.proto
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
v3 "go.unistack.org/micro-client-http/v3"
|
||||
v31 "go.unistack.org/micro-server-http/v3"
|
||||
v31 "go.unistack.org/micro-client-http/v3"
|
||||
v3 "go.unistack.org/micro-server-http/v3"
|
||||
client "go.unistack.org/micro/v3/client"
|
||||
server "go.unistack.org/micro/v3/server"
|
||||
http "net/http"
|
||||
time "time"
|
||||
)
|
||||
|
||||
var (
|
||||
TestDoubleServerEndpoints = []v3.EndpointMetadata{
|
||||
{
|
||||
Name: "TestDouble.CallDouble",
|
||||
Path: "/v1/testdouble/call/name/{name}",
|
||||
Method: "POST",
|
||||
Body: "*",
|
||||
Stream: false,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
type testDoubleClient struct {
|
||||
c client.Client
|
||||
name string
|
||||
@@ -27,12 +39,12 @@ func (c *testDoubleClient) CallDouble(ctx context.Context, req *CallReq, opts ..
|
||||
errmap := make(map[string]interface{}, 1)
|
||||
errmap["default"] = &Error{}
|
||||
opts = append(opts,
|
||||
v3.ErrorMap(errmap),
|
||||
v31.ErrorMap(errmap),
|
||||
)
|
||||
opts = append(opts,
|
||||
v3.Method(http.MethodPost),
|
||||
v3.Path("/v1/testdouble/call/name/{name}"),
|
||||
v3.Body("*"),
|
||||
v31.Method(http.MethodPost),
|
||||
v31.Path("/v1/testdouble/call/name/{name}"),
|
||||
v31.Body("*"),
|
||||
)
|
||||
td := time.Duration(5000000000)
|
||||
opts = append(opts, client.WithRequestTimeout(td))
|
||||
@@ -65,10 +77,43 @@ func RegisterTestDoubleServer(s server.Server, sh TestDoubleServer, opts ...serv
|
||||
}
|
||||
h := &testDoubleServer{sh}
|
||||
var nopts []server.HandlerOption
|
||||
nopts = append(nopts, v31.HandlerEndpoints(TestDoubleServerEndpoints))
|
||||
nopts = append(nopts, v3.HandlerEndpoints(TestDoubleServerEndpoints))
|
||||
return s.Handle(s.NewHandler(&TestDouble{h}, append(nopts, opts...)...))
|
||||
}
|
||||
|
||||
var (
|
||||
TestServerEndpoints = []v3.EndpointMetadata{
|
||||
{
|
||||
Name: "Test.CallRepeatedString",
|
||||
Path: "/v1/test/call_repeated_string",
|
||||
Method: "POST",
|
||||
Body: "*",
|
||||
Stream: false,
|
||||
},
|
||||
{
|
||||
Name: "Test.CallRepeatedInt64",
|
||||
Path: "/v1/test/call_repeated_int64",
|
||||
Method: "POST",
|
||||
Body: "*",
|
||||
Stream: false,
|
||||
},
|
||||
{
|
||||
Name: "Test.Call",
|
||||
Path: "/v1/test/call/{name}",
|
||||
Method: "POST",
|
||||
Body: "*",
|
||||
Stream: false,
|
||||
},
|
||||
{
|
||||
Name: "Test.CallError",
|
||||
Path: "/v1/test/callerror/{name}",
|
||||
Method: "POST",
|
||||
Body: "*",
|
||||
Stream: false,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
type testClient struct {
|
||||
c client.Client
|
||||
name string
|
||||
@@ -82,12 +127,12 @@ func (c *testClient) CallRepeatedString(ctx context.Context, req *CallReq, opts
|
||||
errmap := make(map[string]interface{}, 1)
|
||||
errmap["default"] = &Error{}
|
||||
opts = append(opts,
|
||||
v3.ErrorMap(errmap),
|
||||
v31.ErrorMap(errmap),
|
||||
)
|
||||
opts = append(opts,
|
||||
v3.Method(http.MethodPost),
|
||||
v3.Path("/v1/test/call_repeated_string"),
|
||||
v3.Body("*"),
|
||||
v31.Method(http.MethodPost),
|
||||
v31.Path("/v1/test/call_repeated_string"),
|
||||
v31.Body("*"),
|
||||
)
|
||||
td := time.Duration(5000000000)
|
||||
opts = append(opts, client.WithRequestTimeout(td))
|
||||
@@ -103,12 +148,12 @@ func (c *testClient) CallRepeatedInt64(ctx context.Context, req *CallReq, opts .
|
||||
errmap := make(map[string]interface{}, 1)
|
||||
errmap["default"] = &Error{}
|
||||
opts = append(opts,
|
||||
v3.ErrorMap(errmap),
|
||||
v31.ErrorMap(errmap),
|
||||
)
|
||||
opts = append(opts,
|
||||
v3.Method(http.MethodPost),
|
||||
v3.Path("/v1/test/call_repeated_int64"),
|
||||
v3.Body("*"),
|
||||
v31.Method(http.MethodPost),
|
||||
v31.Path("/v1/test/call_repeated_int64"),
|
||||
v31.Body("*"),
|
||||
)
|
||||
td := time.Duration(5000000000)
|
||||
opts = append(opts, client.WithRequestTimeout(td))
|
||||
@@ -124,16 +169,16 @@ func (c *testClient) Call(ctx context.Context, req *CallReq, opts ...client.Call
|
||||
errmap := make(map[string]interface{}, 1)
|
||||
errmap["default"] = &Error{}
|
||||
opts = append(opts,
|
||||
v3.ErrorMap(errmap),
|
||||
v31.ErrorMap(errmap),
|
||||
)
|
||||
opts = append(opts,
|
||||
v3.Method(http.MethodPost),
|
||||
v3.Path("/v1/test/call/{name}"),
|
||||
v3.Body("*"),
|
||||
v31.Method(http.MethodPost),
|
||||
v31.Path("/v1/test/call/{name}"),
|
||||
v31.Body("*"),
|
||||
)
|
||||
opts = append(opts,
|
||||
v3.Header("Clientid", "true"),
|
||||
v3.Cookie("Csrftoken", "true"),
|
||||
v31.Header("Clientid", "true"),
|
||||
v31.Cookie("Csrftoken", "true"),
|
||||
)
|
||||
td := time.Duration(5000000000)
|
||||
opts = append(opts, client.WithRequestTimeout(td))
|
||||
@@ -149,12 +194,12 @@ func (c *testClient) CallError(ctx context.Context, req *CallReq1, opts ...clien
|
||||
errmap := make(map[string]interface{}, 1)
|
||||
errmap["default"] = &Error{}
|
||||
opts = append(opts,
|
||||
v3.ErrorMap(errmap),
|
||||
v31.ErrorMap(errmap),
|
||||
)
|
||||
opts = append(opts,
|
||||
v3.Method(http.MethodPost),
|
||||
v3.Path("/v1/test/callerror/{name}"),
|
||||
v3.Body("*"),
|
||||
v31.Method(http.MethodPost),
|
||||
v31.Path("/v1/test/callerror/{name}"),
|
||||
v31.Body("*"),
|
||||
)
|
||||
rsp := &CallRsp1{}
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Test.CallError", req), rsp, opts...)
|
||||
@@ -189,9 +234,9 @@ func (h *testServer) Call(ctx context.Context, req *CallReq, rsp *CallRsp) error
|
||||
td := time.Duration(5000000000)
|
||||
ctx, cancel = context.WithTimeout(ctx, td)
|
||||
defer cancel()
|
||||
v31.FillRequest(ctx, req,
|
||||
v31.Header("Clientid", "true"),
|
||||
v31.Cookie("Csrftoken", "true"),
|
||||
v3.FillRequest(ctx, req,
|
||||
v3.Header("Clientid", "true"),
|
||||
v3.Cookie("Csrftoken", "true"),
|
||||
)
|
||||
return h.TestServer.Call(ctx, req, rsp)
|
||||
}
|
||||
@@ -212,6 +257,6 @@ func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOp
|
||||
}
|
||||
h := &testServer{sh}
|
||||
var nopts []server.HandlerOption
|
||||
nopts = append(nopts, v31.HandlerEndpoints(TestServerEndpoints))
|
||||
nopts = append(nopts, v3.HandlerEndpoints(TestServerEndpoints))
|
||||
return s.Handle(s.NewHandler(&Test{h}, append(nopts, opts...)...))
|
||||
}
|
||||
|
Reference in New Issue
Block a user