update after protoc-gen-micro changes
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
package grpc
|
||||
|
||||
//go:generate protoc -I./proto -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --micro_out=paths=source_relative:./proto proto/test.proto
|
||||
//go:generate protoc -I./proto -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --micro_out=standalone=true,paths=source_relative:./gproto proto/test.proto
|
||||
|
42
client/grpc/gproto/test_micro.pb.go
Normal file
42
client/grpc/gproto/test_micro.pb.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// Code generated by protoc-gen-micro
|
||||
// source: test.proto
|
||||
package helloworld
|
||||
|
||||
import (
|
||||
context "context"
|
||||
proto "github.com/unistack-org/micro-tests/client/grpc/proto"
|
||||
api "github.com/unistack-org/micro/v3/api"
|
||||
client "github.com/unistack-org/micro/v3/client"
|
||||
)
|
||||
|
||||
func NewTestEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
type TestClient interface {
|
||||
Call(ctx context.Context, req *proto.Request, opts ...client.CallOption) (*proto.Response, error)
|
||||
Stream(ctx context.Context, opts ...client.CallOption) (Test_StreamClient, error)
|
||||
}
|
||||
|
||||
type Test_StreamClient interface {
|
||||
Context() context.Context
|
||||
SendMsg(msg interface{}) error
|
||||
RecvMsg(msg interface{}) error
|
||||
Close() error
|
||||
Send(msg *proto.Request) error
|
||||
Recv() (*proto.Response, error)
|
||||
}
|
||||
|
||||
type TestServer interface {
|
||||
Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error
|
||||
Stream(ctx context.Context, stream Test_StreamStream) error
|
||||
}
|
||||
|
||||
type Test_StreamStream interface {
|
||||
Context() context.Context
|
||||
SendMsg(msg interface{}) error
|
||||
RecvMsg(msg interface{}) error
|
||||
Close() error
|
||||
Recv() (*proto.Request, error)
|
||||
Send(msg *proto.Response) error
|
||||
}
|
128
client/grpc/gproto/test_micro_rpc.pb.go
Normal file
128
client/grpc/gproto/test_micro_rpc.pb.go
Normal file
@@ -0,0 +1,128 @@
|
||||
// Code generated by protoc-gen-micro
|
||||
// source: test.proto
|
||||
package helloworld
|
||||
|
||||
import (
|
||||
context "context"
|
||||
proto "github.com/unistack-org/micro-tests/client/grpc/proto"
|
||||
api "github.com/unistack-org/micro/v3/api"
|
||||
client "github.com/unistack-org/micro/v3/client"
|
||||
server "github.com/unistack-org/micro/v3/server"
|
||||
)
|
||||
|
||||
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 *proto.Request, opts ...client.CallOption) (*proto.Response, error) {
|
||||
rsp := &proto.Response{}
|
||||
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) 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...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &testClientStream{stream}, nil
|
||||
}
|
||||
|
||||
type testClientStream struct {
|
||||
stream client.Stream
|
||||
}
|
||||
|
||||
func (s *testClientStream) Close() error {
|
||||
return s.stream.Close()
|
||||
}
|
||||
|
||||
func (s *testClientStream) Context() context.Context {
|
||||
return s.stream.Context()
|
||||
}
|
||||
|
||||
func (s *testClientStream) SendMsg(msg interface{}) error {
|
||||
return s.stream.Send(msg)
|
||||
}
|
||||
|
||||
func (s *testClientStream) RecvMsg(msg interface{}) error {
|
||||
return s.stream.Recv(msg)
|
||||
}
|
||||
|
||||
func (s *testClientStream) Send(msg *proto.Request) error {
|
||||
return s.stream.Send(msg)
|
||||
}
|
||||
|
||||
func (s *testClientStream) Recv() (*proto.Response, error) {
|
||||
msg := &proto.Response{}
|
||||
if err := s.stream.Recv(msg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
type testServer struct {
|
||||
TestServer
|
||||
}
|
||||
|
||||
func (h *testServer) Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error {
|
||||
return h.TestServer.Call(ctx, req, rsp)
|
||||
}
|
||||
|
||||
func (h *testServer) Stream(ctx context.Context, stream server.Stream) error {
|
||||
return h.TestServer.Stream(ctx, &testStreamStream{stream})
|
||||
}
|
||||
|
||||
type testStreamStream struct {
|
||||
stream server.Stream
|
||||
}
|
||||
|
||||
func (s *testStreamStream) Close() error {
|
||||
return s.stream.Close()
|
||||
}
|
||||
|
||||
func (s *testStreamStream) Context() context.Context {
|
||||
return s.stream.Context()
|
||||
}
|
||||
|
||||
func (s *testStreamStream) SendMsg(msg interface{}) error {
|
||||
return s.stream.Send(msg)
|
||||
}
|
||||
|
||||
func (s *testStreamStream) RecvMsg(msg interface{}) error {
|
||||
return s.stream.Recv(msg)
|
||||
}
|
||||
|
||||
func (s *testStreamStream) Send(msg *proto.Response) error {
|
||||
return s.stream.Send(msg)
|
||||
}
|
||||
|
||||
func (s *testStreamStream) Recv() (*proto.Request, error) {
|
||||
msg := &proto.Request{}
|
||||
if err := s.stream.Recv(msg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
func RegisterTestServer(s server.Server, sh TestServer, opts ...server.HandlerOption) error {
|
||||
type test interface {
|
||||
Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error
|
||||
Stream(ctx context.Context, stream server.Stream) 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...))
|
||||
}
|
@@ -144,8 +144,11 @@ var file_test_proto_rawDesc = []byte{
|
||||
0x12, 0x13, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72,
|
||||
0x6c, 0x64, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30,
|
||||
0x01, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x3b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c,
|
||||
0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x01, 0x42, 0x42, 0x5a, 0x40, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
|
||||
0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2d, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63,
|
||||
0x72, 0x6f, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f,
|
||||
0x67, 0x72, 0x70, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
|
||||
0x77, 0x6f, 0x72, 0x6c, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
@@ -1,7 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package helloworld;
|
||||
option go_package = ".;helloworld";
|
||||
option go_package = "github.com/unistack-org/micro-tests/client/grpc/proto;helloworld";
|
||||
|
||||
service Test {
|
||||
rpc Call(Request) returns (Response) {};
|
||||
|
@@ -1,3 +1,3 @@
|
||||
package http
|
||||
|
||||
//go:generate protoc -I./proto -I. -I/home/vtolstov/.cache/go-path/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/v2@v2.1.0 -I/home/vtolstov/.cache/go-path/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/v2@v2.1.0/third_party/googleapis --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --micro_out=components=micro|http,debug=true,paths=source_relative:./proto proto/github.proto
|
||||
//go:generate protoc -I./proto -I. -I/home/vtolstov/.cache/go-path/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/v2@v2.1.0 -I/home/vtolstov/.cache/go-path/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/v2@v2.1.0/third_party/googleapis --go_out=paths=source_relative:./proto --micro_out=components=micro|http,debug=true,paths=source_relative:./proto proto/github.proto
|
||||
|
@@ -62,7 +62,7 @@ func TestError(t *testing.T) {
|
||||
|
||||
func TestNative(t *testing.T) {
|
||||
c := client.NewClientCallOptions(mhttp.NewClient(client.ContentType("application/json"), client.Codec("application/json", jsoncodec.NewCodec())), client.WithAddress("https://api.github.com"))
|
||||
gh := pb.NewGithubService("github", c)
|
||||
gh := pb.NewGithubClient("github", c)
|
||||
|
||||
rsp, err := gh.LookupUser(context.TODO(), &pb.LookupUserReq{Username: "vtolstov"})
|
||||
if err != nil {
|
||||
|
@@ -1,90 +0,0 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
const _ = grpc.SupportPackageIsVersion6
|
||||
|
||||
// GithubClient is the client API for Github service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type GithubClient interface {
|
||||
LookupUser(ctx context.Context, in *LookupUserReq, opts ...grpc.CallOption) (*LookupUserRsp, error)
|
||||
}
|
||||
|
||||
type githubClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewGithubClient(cc grpc.ClientConnInterface) GithubClient {
|
||||
return &githubClient{cc}
|
||||
}
|
||||
|
||||
func (c *githubClient) LookupUser(ctx context.Context, in *LookupUserReq, opts ...grpc.CallOption) (*LookupUserRsp, error) {
|
||||
out := new(LookupUserRsp)
|
||||
err := c.cc.Invoke(ctx, "/github.Github/LookupUser", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// GithubServer is the server API for Github service.
|
||||
// All implementations must embed UnimplementedGithubServer
|
||||
// for forward compatibility
|
||||
type GithubServer interface {
|
||||
LookupUser(context.Context, *LookupUserReq) (*LookupUserRsp, error)
|
||||
mustEmbedUnimplementedGithubServer()
|
||||
}
|
||||
|
||||
// UnimplementedGithubServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedGithubServer struct {
|
||||
}
|
||||
|
||||
func (*UnimplementedGithubServer) LookupUser(context.Context, *LookupUserReq) (*LookupUserRsp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method LookupUser not implemented")
|
||||
}
|
||||
func (*UnimplementedGithubServer) mustEmbedUnimplementedGithubServer() {}
|
||||
|
||||
func RegisterGithubServer(s *grpc.Server, srv GithubServer) {
|
||||
s.RegisterService(&_Github_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _Github_LookupUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(LookupUserReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(GithubServer).LookupUser(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/github.Github/LookupUser",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(GithubServer).LookupUser(ctx, req.(*LookupUserReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var _Github_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "github.Github",
|
||||
HandlerType: (*GithubServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "LookupUser",
|
||||
Handler: _Github_LookupUser_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "github.proto",
|
||||
}
|
@@ -3,49 +3,26 @@
|
||||
package pb
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
micro_api "github.com/unistack-org/micro/v3/api"
|
||||
micro_client "github.com/unistack-org/micro/v3/client"
|
||||
micro_server "github.com/unistack-org/micro/v3/server"
|
||||
context "context"
|
||||
api "github.com/unistack-org/micro/v3/api"
|
||||
client "github.com/unistack-org/micro/v3/client"
|
||||
)
|
||||
|
||||
// NewGithubEndpoints provides api endpoints metdata for Github service
|
||||
func NewGithubEndpoints() []*micro_api.Endpoint {
|
||||
var endpoints []*micro_api.Endpoint
|
||||
endpoint := µ_api.Endpoint{
|
||||
Name: "Github.LookupUser",
|
||||
Path: []string{"/users/{username}"},
|
||||
Method: []string{"GET"},
|
||||
Handler: "rpc",
|
||||
func NewGithubEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{
|
||||
&api.Endpoint{
|
||||
Name: "Github.LookupUser",
|
||||
Path: []string{"/users/{username}"},
|
||||
Method: []string{"GET"},
|
||||
Handler: "rpc",
|
||||
},
|
||||
}
|
||||
endpoints = append(endpoints, endpoint)
|
||||
return endpoints
|
||||
}
|
||||
|
||||
// GithubService interface
|
||||
type GithubService interface {
|
||||
LookupUser(context.Context, *LookupUserReq, ...micro_client.CallOption) (*LookupUserRsp, error)
|
||||
type GithubClient interface {
|
||||
LookupUser(ctx context.Context, req *LookupUserReq, opts ...client.CallOption) (*LookupUserRsp, error)
|
||||
}
|
||||
|
||||
// Micro server stuff
|
||||
|
||||
// GithubHandler server handler
|
||||
type GithubHandler interface {
|
||||
LookupUser(context.Context, *LookupUserReq, *LookupUserRsp) error
|
||||
}
|
||||
|
||||
// RegisterGithubHandler registers server handler
|
||||
func RegisterGithubHandler(s micro_server.Server, sh GithubHandler, opts ...micro_server.HandlerOption) error {
|
||||
type github interface {
|
||||
LookupUser(context.Context, *LookupUserReq, *LookupUserRsp) error
|
||||
}
|
||||
type Github struct {
|
||||
github
|
||||
}
|
||||
h := &githubHandler{sh}
|
||||
for _, endpoint := range NewGithubEndpoints() {
|
||||
opts = append(opts, micro_api.WithEndpoint(endpoint))
|
||||
}
|
||||
return s.Handle(s.NewHandler(&Github{h}, opts...))
|
||||
type GithubServer interface {
|
||||
LookupUser(ctx context.Context, req *LookupUserReq, rsp *LookupUserRsp) error
|
||||
}
|
||||
|
@@ -3,58 +3,57 @@
|
||||
package pb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
micro_client_http "github.com/unistack-org/micro-client-http/v3"
|
||||
micro_client "github.com/unistack-org/micro/v3/client"
|
||||
micro_server "github.com/unistack-org/micro/v3/server"
|
||||
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"
|
||||
)
|
||||
|
||||
var (
|
||||
_ micro_server.Option
|
||||
_ micro_client.Option
|
||||
)
|
||||
|
||||
type githubService struct {
|
||||
c micro_client.Client
|
||||
type githubClient struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
// Micro client stuff
|
||||
|
||||
// NewGithubService create new service client
|
||||
func NewGithubService(name string, c micro_client.Client) GithubService {
|
||||
return &githubService{c: c, name: name}
|
||||
func NewGithubClient(name string, c client.Client) GithubClient {
|
||||
return &githubClient{c: c, name: name}
|
||||
}
|
||||
|
||||
func (c *githubService) LookupUser(ctx context.Context, req *LookupUserReq, opts ...micro_client.CallOption) (*LookupUserRsp, error) {
|
||||
func (c *githubClient) LookupUser(ctx context.Context, req *LookupUserReq, opts ...client.CallOption) (*LookupUserRsp, error) {
|
||||
errmap := make(map[string]interface{}, 1)
|
||||
errmap["default"] = &Error{}
|
||||
nopts := append(opts,
|
||||
micro_client_http.Method("GET"),
|
||||
micro_client_http.Path("/users/{username}"),
|
||||
micro_client_http.ErrorMap(errmap),
|
||||
opts = append(opts,
|
||||
v3.ErrorMap(errmap),
|
||||
v3.Method("GET"),
|
||||
v3.Path("/users/{username}"),
|
||||
v3.Body(""),
|
||||
)
|
||||
rsp := &LookupUserRsp{}
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Github.LookupUser", req), rsp, nopts...)
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Github.LookupUser", req), rsp, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
// Error method to satisfy error interface
|
||||
func (e *Error) Error() string {
|
||||
return fmt.Sprintf("%#v", e)
|
||||
type githubServer struct {
|
||||
GithubServer
|
||||
}
|
||||
|
||||
// Micro server stuff
|
||||
|
||||
type githubHandler struct {
|
||||
GithubHandler
|
||||
func (h *githubServer) LookupUser(ctx context.Context, req *LookupUserReq, rsp *LookupUserRsp) error {
|
||||
return h.GithubServer.LookupUser(ctx, req, rsp)
|
||||
}
|
||||
|
||||
func (h *githubHandler) LookupUser(ctx context.Context, req *LookupUserReq, rsp *LookupUserRsp) error {
|
||||
return h.GithubHandler.LookupUser(ctx, req, rsp)
|
||||
func RegisterGithubServer(s server.Server, sh GithubServer, opts ...server.HandlerOption) error {
|
||||
type github interface {
|
||||
LookupUser(ctx context.Context, req *LookupUserReq, rsp *LookupUserRsp) error
|
||||
}
|
||||
type Github struct {
|
||||
github
|
||||
}
|
||||
h := &githubServer{sh}
|
||||
for _, endpoint := range NewGithubEndpoints() {
|
||||
opts = append(opts, api.WithEndpoint(endpoint))
|
||||
}
|
||||
return s.Handle(s.NewHandler(&Github{h}, opts...))
|
||||
}
|
||||
|
Reference in New Issue
Block a user