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 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