From 67d5795e893298b1a981d7ce743885dab655b1ff Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 5 May 2023 20:06:27 +0300 Subject: [PATCH] move to micro v4 Signed-off-by: Vasiliy Tolstov --- generate.go | 2 +- go.mod | 15 +--- micro/service_micro.pb.go | 16 ++-- micro/service_micro_grpc.pb.go | 46 +++++------ options.go | 4 +- proto/service.pb.go | 34 ++++---- proto/service.proto | 4 +- proto/service_grpc.pb.go | 146 --------------------------------- service.go | 12 +-- 9 files changed, 62 insertions(+), 217 deletions(-) delete mode 100644 proto/service_grpc.pb.go diff --git a/generate.go b/generate.go index f0f8c44..07324fb 100644 --- a/generate.go +++ b/generate.go @@ -1,3 +1,3 @@ package service -//go:generate protoc -I./proto -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --go-micro_out=components=micro|grpc,standalone=true,debug=true,paths=source_relative:./micro proto/service.proto +//go:generate protoc -I./proto -I. --go_out=paths=source_relative:./proto --go-micro_out=components=micro|grpc,standalone=true,debug=true,paths=source_relative:./micro proto/service.proto diff --git a/go.mod b/go.mod index 5294ee0..a94478d 100644 --- a/go.mod +++ b/go.mod @@ -1,19 +1,10 @@ -module go.unistack.org/micro-config-service/v3 +module go.unistack.org/micro-config-service/v4 -go 1.18 +go 1.20 require ( github.com/imdario/mergo v0.3.13 - go.unistack.org/micro-server-http/v3 v3.10.13 - go.unistack.org/micro/v3 v3.10.16 + go.unistack.org/micro/v4 v4.0.1 google.golang.org/grpc v1.52.3 google.golang.org/protobuf v1.28.1 ) - -require ( - github.com/golang/protobuf v1.5.2 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect - google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect -) diff --git a/micro/service_micro.pb.go b/micro/service_micro.pb.go index c8be5ea..ab5b0a9 100644 --- a/micro/service_micro.pb.go +++ b/micro/service_micro.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-micro. DO NOT EDIT. // versions: -// - protoc-gen-go-micro v3.10.2 +// - protoc-gen-go-micro v4.0.0 // - protoc v3.21.12 // source: service.proto @@ -8,24 +8,24 @@ package servicepb import ( context "context" - proto "go.unistack.org/micro-config-service/v3/proto" - v3 "go.unistack.org/micro-server-http/v3" - client "go.unistack.org/micro/v3/client" + proto "go.unistack.org/micro-config-service/v4/proto" + v4 "go.unistack.org/micro-server-http/v4" + client "go.unistack.org/micro/v4/client" ) var ( - ConfigName = "Config" + ConfigServiceName = "ConfigService" ) var ( - ConfigServerEndpoints = []v3.EndpointMetadata{} + ConfigServiceServerEndpoints = []v4.EndpointMetadata{} ) -type ConfigClient interface { +type ConfigServiceClient interface { Load(ctx context.Context, req *proto.LoadRequest, opts ...client.CallOption) (*proto.LoadResponse, error) Save(ctx context.Context, req *proto.SaveRequest, opts ...client.CallOption) (*proto.SaveResponse, error) } -type ConfigServer interface { +type ConfigServiceServer interface { Load(ctx context.Context, req *proto.LoadRequest, rsp *proto.LoadResponse) error Save(ctx context.Context, req *proto.SaveRequest, rsp *proto.SaveResponse) error } diff --git a/micro/service_micro_grpc.pb.go b/micro/service_micro_grpc.pb.go index 1b77e15..e1f481d 100644 --- a/micro/service_micro_grpc.pb.go +++ b/micro/service_micro_grpc.pb.go @@ -1,64 +1,64 @@ // Code generated by protoc-gen-go-micro. DO NOT EDIT. -// protoc-gen-go-micro version: v3.10.2 +// protoc-gen-go-micro version: v4.0.0 // source: service.proto package servicepb import ( context "context" - proto "go.unistack.org/micro-config-service/v3/proto" - client "go.unistack.org/micro/v3/client" - server "go.unistack.org/micro/v3/server" + proto "go.unistack.org/micro-config-service/v4/proto" + client "go.unistack.org/micro/v4/client" + server "go.unistack.org/micro/v4/server" ) -type configClient struct { +type configServiceClient struct { c client.Client name string } -func NewConfigClient(name string, c client.Client) ConfigClient { - return &configClient{c: c, name: name} +func NewConfigServiceClient(name string, c client.Client) ConfigServiceClient { + return &configServiceClient{c: c, name: name} } -func (c *configClient) Load(ctx context.Context, req *proto.LoadRequest, opts ...client.CallOption) (*proto.LoadResponse, error) { +func (c *configServiceClient) Load(ctx context.Context, req *proto.LoadRequest, opts ...client.CallOption) (*proto.LoadResponse, error) { rsp := &proto.LoadResponse{} - err := c.c.Call(ctx, c.c.NewRequest(c.name, "Config.Load", req), rsp, opts...) + err := c.c.Call(ctx, c.c.NewRequest(c.name, "ConfigService.Load", req), rsp, opts...) if err != nil { return nil, err } return rsp, nil } -func (c *configClient) Save(ctx context.Context, req *proto.SaveRequest, opts ...client.CallOption) (*proto.SaveResponse, error) { +func (c *configServiceClient) Save(ctx context.Context, req *proto.SaveRequest, opts ...client.CallOption) (*proto.SaveResponse, error) { rsp := &proto.SaveResponse{} - err := c.c.Call(ctx, c.c.NewRequest(c.name, "Config.Save", req), rsp, opts...) + err := c.c.Call(ctx, c.c.NewRequest(c.name, "ConfigService.Save", req), rsp, opts...) if err != nil { return nil, err } return rsp, nil } -type configServer struct { - ConfigServer +type configServiceServer struct { + ConfigServiceServer } -func (h *configServer) Load(ctx context.Context, req *proto.LoadRequest, rsp *proto.LoadResponse) error { - return h.ConfigServer.Load(ctx, req, rsp) +func (h *configServiceServer) Load(ctx context.Context, req *proto.LoadRequest, rsp *proto.LoadResponse) error { + return h.ConfigServiceServer.Load(ctx, req, rsp) } -func (h *configServer) Save(ctx context.Context, req *proto.SaveRequest, rsp *proto.SaveResponse) error { - return h.ConfigServer.Save(ctx, req, rsp) +func (h *configServiceServer) Save(ctx context.Context, req *proto.SaveRequest, rsp *proto.SaveResponse) error { + return h.ConfigServiceServer.Save(ctx, req, rsp) } -func RegisterConfigServer(s server.Server, sh ConfigServer, opts ...server.HandlerOption) error { - type config interface { +func RegisterConfigServiceServer(s server.Server, sh ConfigServiceServer, opts ...server.HandlerOption) error { + type configService interface { Load(ctx context.Context, req *proto.LoadRequest, rsp *proto.LoadResponse) error Save(ctx context.Context, req *proto.SaveRequest, rsp *proto.SaveResponse) error } - type Config struct { - config + type ConfigService struct { + configService } - h := &configServer{sh} + h := &configServiceServer{sh} var nopts []server.HandlerOption - return s.Handle(s.NewHandler(&Config{h}, append(nopts, opts...)...)) + return s.Handle(s.NewHandler(&ConfigService{h}, append(nopts, opts...)...)) } diff --git a/options.go b/options.go index 5816698..785eae8 100644 --- a/options.go +++ b/options.go @@ -1,8 +1,8 @@ package service import ( - "go.unistack.org/micro/v3/client" - "go.unistack.org/micro/v3/config" + "go.unistack.org/micro/v4/client" + "go.unistack.org/micro/v4/config" ) type clientKey struct{} diff --git a/proto/service.pb.go b/proto/service.pb.go index 38e6df5..9d7d0e6 100644 --- a/proto/service.pb.go +++ b/proto/service.pb.go @@ -221,19 +221,19 @@ var file_service_proto_rawDesc = []byte{ 0x69, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x22, 0x0e, 0x0a, 0x0c, 0x53, 0x61, - 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x76, 0x0a, 0x06, 0x43, 0x6f, - 0x6e, 0x66, 0x69, 0x67, 0x12, 0x35, 0x0a, 0x04, 0x4c, 0x6f, 0x61, 0x64, 0x12, 0x14, 0x2e, 0x73, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, 0x61, - 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x04, 0x53, - 0x61, 0x76, 0x65, 0x12, 0x14, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x53, 0x61, - 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x73, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x00, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x6f, 0x2e, 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, - 0x6b, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x63, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x3b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x7d, 0x0a, 0x0d, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x35, 0x0a, 0x04, 0x4c, + 0x6f, 0x61, 0x64, 0x12, 0x14, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, + 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x73, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x00, 0x12, 0x35, 0x0a, 0x04, 0x53, 0x61, 0x76, 0x65, 0x12, 0x14, 0x2e, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x15, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x6f, 0x2e, + 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, + 0x72, 0x6f, 0x2d, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x2f, 0x76, 0x34, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -256,10 +256,10 @@ var file_service_proto_goTypes = []interface{}{ (*SaveResponse)(nil), // 3: service.SaveResponse } var file_service_proto_depIdxs = []int32{ - 0, // 0: service.Config.Load:input_type -> service.LoadRequest - 2, // 1: service.Config.Save:input_type -> service.SaveRequest - 1, // 2: service.Config.Load:output_type -> service.LoadResponse - 3, // 3: service.Config.Save:output_type -> service.SaveResponse + 0, // 0: service.ConfigService.Load:input_type -> service.LoadRequest + 2, // 1: service.ConfigService.Save:input_type -> service.SaveRequest + 1, // 2: service.ConfigService.Load:output_type -> service.LoadResponse + 3, // 3: service.ConfigService.Save:output_type -> service.SaveResponse 2, // [2:4] is the sub-list for method output_type 0, // [0:2] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name diff --git a/proto/service.proto b/proto/service.proto index a495ae1..1147f27 100644 --- a/proto/service.proto +++ b/proto/service.proto @@ -1,9 +1,9 @@ syntax = "proto3"; package service; -option go_package="go.unistack.org/micro-config-service/v3/proto;servicepb"; +option go_package="go.unistack.org/micro-config-service/v4/proto;servicepb"; -service Config { +service ConfigService { rpc Load(LoadRequest) returns (LoadResponse) {}; rpc Save(SaveRequest) returns (SaveResponse) {}; } diff --git a/proto/service_grpc.pb.go b/proto/service_grpc.pb.go deleted file mode 100644 index a68440a..0000000 --- a/proto/service_grpc.pb.go +++ /dev/null @@ -1,146 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.3.0 -// - protoc v3.21.12 -// source: service.proto - -package servicepb - -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. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 - -const ( - Config_Load_FullMethodName = "/service.Config/Load" - Config_Save_FullMethodName = "/service.Config/Save" -) - -// ConfigClient is the client API for Config 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 ConfigClient interface { - Load(ctx context.Context, in *LoadRequest, opts ...grpc.CallOption) (*LoadResponse, error) - Save(ctx context.Context, in *SaveRequest, opts ...grpc.CallOption) (*SaveResponse, error) -} - -type configClient struct { - cc grpc.ClientConnInterface -} - -func NewConfigClient(cc grpc.ClientConnInterface) ConfigClient { - return &configClient{cc} -} - -func (c *configClient) Load(ctx context.Context, in *LoadRequest, opts ...grpc.CallOption) (*LoadResponse, error) { - out := new(LoadResponse) - err := c.cc.Invoke(ctx, Config_Load_FullMethodName, in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *configClient) Save(ctx context.Context, in *SaveRequest, opts ...grpc.CallOption) (*SaveResponse, error) { - out := new(SaveResponse) - err := c.cc.Invoke(ctx, Config_Save_FullMethodName, in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// ConfigServer is the server API for Config service. -// All implementations must embed UnimplementedConfigServer -// for forward compatibility -type ConfigServer interface { - Load(context.Context, *LoadRequest) (*LoadResponse, error) - Save(context.Context, *SaveRequest) (*SaveResponse, error) - mustEmbedUnimplementedConfigServer() -} - -// UnimplementedConfigServer must be embedded to have forward compatible implementations. -type UnimplementedConfigServer struct { -} - -func (UnimplementedConfigServer) Load(context.Context, *LoadRequest) (*LoadResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Load not implemented") -} -func (UnimplementedConfigServer) Save(context.Context, *SaveRequest) (*SaveResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Save not implemented") -} -func (UnimplementedConfigServer) mustEmbedUnimplementedConfigServer() {} - -// UnsafeConfigServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to ConfigServer will -// result in compilation errors. -type UnsafeConfigServer interface { - mustEmbedUnimplementedConfigServer() -} - -func RegisterConfigServer(s grpc.ServiceRegistrar, srv ConfigServer) { - s.RegisterService(&Config_ServiceDesc, srv) -} - -func _Config_Load_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(LoadRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ConfigServer).Load(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Config_Load_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ConfigServer).Load(ctx, req.(*LoadRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Config_Save_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SaveRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ConfigServer).Save(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Config_Save_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ConfigServer).Save(ctx, req.(*SaveRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// Config_ServiceDesc is the grpc.ServiceDesc for Config service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Config_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "service.Config", - HandlerType: (*ConfigServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Load", - Handler: _Config_Load_Handler, - }, - { - MethodName: "Save", - Handler: _Config_Save_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "service.proto", -} diff --git a/service.go b/service.go index 1c6593a..a52fa75 100644 --- a/service.go +++ b/service.go @@ -1,15 +1,15 @@ -package service // import "go.unistack.org/micro-config-service/v3" +package service // import "go.unistack.org/micro-config-service/v4" import ( "context" "fmt" "github.com/imdario/mergo" - pbmicro "go.unistack.org/micro-config-service/v3/micro" - pb "go.unistack.org/micro-config-service/v3/proto" - "go.unistack.org/micro/v3/client" - "go.unistack.org/micro/v3/config" - rutil "go.unistack.org/micro/v3/util/reflect" + pbmicro "go.unistack.org/micro-config-service/v4/micro" + pb "go.unistack.org/micro-config-service/v4/proto" + "go.unistack.org/micro/v4/client" + "go.unistack.org/micro/v4/config" + rutil "go.unistack.org/micro/v4/util/reflect" ) var _ config.Config = &serviceConfig{}