micro-tests/server/http/proto/test_micro_http.pb.go
Vasiliy Tolstov b5c7da9b7e fixup
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-02-28 01:45:22 +03:00

87 lines
2.3 KiB
Go

// Code generated by protoc-gen-micro
// source: test.proto
package pb
import (
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"
time "time"
)
type testClient struct {
c client.Client
name string
}
func NewTestClient(name string, c client.Client) TestClient {
return &testClient{c: c, name: name}
}
func (c *testClient) Call(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error) {
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v3.Method("POST"),
v3.Path("/v1/test/call/{name}"),
v3.Body("*"),
)
opts = append(opts, client.WithRequestTimeout(time.Second*5))
rsp := &CallRsp{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Test.Call", req), rsp, opts...)
if err != nil {
return nil, err
}
return rsp, nil
}
func (c *testClient) CallError(ctx context.Context, req *CallReq1, opts ...client.CallOption) (*CallRsp1, error) {
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v3.Method("POST"),
v3.Path("/v1/test/callerror/{name}"),
v3.Body("*"),
)
rsp := &CallRsp1{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Test.CallError", req), rsp, opts...)
if err != nil {
return nil, err
}
return rsp, nil
}
type testServer struct {
TestServer
}
func (h *testServer) Call(ctx context.Context, req *CallReq, rsp *CallRsp) error {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, time.Second*5)
defer cancel()
return h.TestServer.Call(ctx, req, rsp)
}
func (h *testServer) CallError(ctx context.Context, req *CallReq1, rsp *CallRsp1) error {
return h.TestServer.CallError(ctx, req, rsp)
}
func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOption) error {
type test interface {
Call(ctx context.Context, req *CallReq, rsp *CallRsp) error
CallError(ctx context.Context, req *CallReq1, rsp *CallRsp1) error
}
type Test struct {
test
}
h := &testServer{sh}
for _, endpoint := range NewTestEndpoints() {
opts = append(opts, api.WithEndpoint(endpoint))
}
return s.Handle(s.NewHandler(&Test{h}, opts...))
}