2021-02-06 19:08:01 +03:00
|
|
|
// Code generated by protoc-gen-micro
|
|
|
|
// source: test.proto
|
|
|
|
package pb
|
|
|
|
|
|
|
|
import (
|
2021-02-27 13:51:39 +03:00
|
|
|
context "context"
|
|
|
|
v3 "github.com/unistack-org/micro-client-http/v3"
|
|
|
|
api "github.com/unistack-org/micro/v3/api"
|
|
|
|
client "github.com/unistack-org/micro/v3/client"
|
|
|
|
server "github.com/unistack-org/micro/v3/server"
|
2021-02-28 01:45:22 +03:00
|
|
|
time "time"
|
2021-02-06 19:08:01 +03:00
|
|
|
)
|
|
|
|
|
2021-02-27 13:51:39 +03:00
|
|
|
type testClient struct {
|
|
|
|
c client.Client
|
2021-02-06 19:08:01 +03:00
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
2021-02-27 13:51:39 +03:00
|
|
|
func NewTestClient(name string, c client.Client) TestClient {
|
|
|
|
return &testClient{c: c, name: name}
|
2021-02-06 19:08:01 +03:00
|
|
|
}
|
|
|
|
|
2021-02-27 13:51:39 +03:00
|
|
|
func (c *testClient) Call(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error) {
|
2021-02-06 19:08:01 +03:00
|
|
|
errmap := make(map[string]interface{}, 1)
|
|
|
|
errmap["default"] = &Error{}
|
2021-02-27 13:51:39 +03:00
|
|
|
opts = append(opts,
|
|
|
|
v3.ErrorMap(errmap),
|
|
|
|
v3.Method("POST"),
|
|
|
|
v3.Path("/v1/test/call/{name}"),
|
|
|
|
v3.Body("*"),
|
2021-02-06 19:08:01 +03:00
|
|
|
)
|
2021-02-28 01:45:22 +03:00
|
|
|
opts = append(opts, client.WithRequestTimeout(time.Second*5))
|
2021-02-06 19:08:01 +03:00
|
|
|
rsp := &CallRsp{}
|
2021-02-27 13:51:39 +03:00
|
|
|
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Test.Call", req), rsp, opts...)
|
2021-02-06 19:08:01 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return rsp, nil
|
|
|
|
}
|
|
|
|
|
2021-02-27 13:51:39 +03:00
|
|
|
func (c *testClient) CallError(ctx context.Context, req *CallReq1, opts ...client.CallOption) (*CallRsp1, error) {
|
2021-02-06 19:08:01 +03:00
|
|
|
errmap := make(map[string]interface{}, 1)
|
|
|
|
errmap["default"] = &Error{}
|
2021-02-27 13:51:39 +03:00
|
|
|
opts = append(opts,
|
|
|
|
v3.ErrorMap(errmap),
|
|
|
|
v3.Method("POST"),
|
|
|
|
v3.Path("/v1/test/callerror/{name}"),
|
|
|
|
v3.Body("*"),
|
2021-02-06 19:08:01 +03:00
|
|
|
)
|
|
|
|
rsp := &CallRsp1{}
|
2021-02-27 13:51:39 +03:00
|
|
|
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Test.CallError", req), rsp, opts...)
|
2021-02-06 19:08:01 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return rsp, nil
|
|
|
|
}
|
|
|
|
|
2021-02-27 13:51:39 +03:00
|
|
|
type testServer struct {
|
|
|
|
TestServer
|
2021-02-06 19:08:01 +03:00
|
|
|
}
|
|
|
|
|
2021-02-27 13:51:39 +03:00
|
|
|
func (h *testServer) Call(ctx context.Context, req *CallReq, rsp *CallRsp) error {
|
2021-02-28 01:45:22 +03:00
|
|
|
var cancel context.CancelFunc
|
|
|
|
ctx, cancel = context.WithTimeout(ctx, time.Second*5)
|
|
|
|
defer cancel()
|
2021-02-27 13:51:39 +03:00
|
|
|
return h.TestServer.Call(ctx, req, rsp)
|
2021-02-06 19:08:01 +03:00
|
|
|
}
|
|
|
|
|
2021-02-27 13:51:39 +03:00
|
|
|
func (h *testServer) CallError(ctx context.Context, req *CallReq1, rsp *CallRsp1) error {
|
|
|
|
return h.TestServer.CallError(ctx, req, rsp)
|
2021-02-06 19:08:01 +03:00
|
|
|
}
|
|
|
|
|
2021-02-27 13:51:39 +03:00
|
|
|
func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOption) error {
|
2021-02-06 19:08:01 +03:00
|
|
|
type test interface {
|
2021-02-27 13:51:39 +03:00
|
|
|
Call(ctx context.Context, req *CallReq, rsp *CallRsp) error
|
|
|
|
CallError(ctx context.Context, req *CallReq1, rsp *CallRsp1) error
|
2021-02-06 19:08:01 +03:00
|
|
|
}
|
|
|
|
type Test struct {
|
|
|
|
test
|
|
|
|
}
|
2021-02-27 13:51:39 +03:00
|
|
|
h := &testServer{sh}
|
2021-02-06 19:08:01 +03:00
|
|
|
for _, endpoint := range NewTestEndpoints() {
|
2021-02-27 13:51:39 +03:00
|
|
|
opts = append(opts, api.WithEndpoint(endpoint))
|
2021-02-06 19:08:01 +03:00
|
|
|
}
|
|
|
|
return s.Handle(s.NewHandler(&Test{h}, opts...))
|
|
|
|
}
|