From f2a0aa0a63765112635b3ca47b4c360ef4dd41b9 Mon Sep 17 00:00:00 2001 From: DasSkelett Date: Thu, 31 Mar 2022 15:15:54 +0200 Subject: [PATCH 1/2] Run go fmt --- cmd/migrate/main.go | 3 ++- main.go | 3 ++- pkg/authnz/authruntime/runtime.go | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/migrate/main.go b/cmd/migrate/main.go index e5eab997..093e091c 100644 --- a/cmd/migrate/main.go +++ b/cmd/migrate/main.go @@ -1,8 +1,9 @@ package migrate import ( - "github.com/pkg/errors" "github.com/freifunkMUC/wg-access-server/internal/storage" + + "github.com/pkg/errors" "github.com/sirupsen/logrus" "gopkg.in/alecthomas/kingpin.v2" ) diff --git a/main.go b/main.go index 4a8041af..4833b616 100644 --- a/main.go +++ b/main.go @@ -6,10 +6,11 @@ import ( "path/filepath" "runtime" - "github.com/pkg/errors" "github.com/freifunkMUC/wg-access-server/cmd" "github.com/freifunkMUC/wg-access-server/cmd/migrate" "github.com/freifunkMUC/wg-access-server/cmd/serve" + + "github.com/pkg/errors" "github.com/sirupsen/logrus" "gopkg.in/alecthomas/kingpin.v2" ) diff --git a/pkg/authnz/authruntime/runtime.go b/pkg/authnz/authruntime/runtime.go index 03fceee6..00e4fb02 100644 --- a/pkg/authnz/authruntime/runtime.go +++ b/pkg/authnz/authruntime/runtime.go @@ -3,9 +3,10 @@ package authruntime import ( "net/http" + "github.com/freifunkMUC/wg-access-server/pkg/authnz/authsession" + "github.com/gorilla/mux" "github.com/gorilla/sessions" - "github.com/freifunkMUC/wg-access-server/pkg/authnz/authsession" ) type Provider struct { From 979f0ffd2571134587dff9b21cf85e991a3c6b61 Mon Sep 17 00:00:00 2001 From: DasSkelett Date: Sat, 2 Apr 2022 15:31:03 +0200 Subject: [PATCH 2/2] Replace depr. github.com/golang/protobuf with google.golang.org/protobuf --- codegen.sh | 6 +- go.mod | 4 +- go.sum | 3 +- internal/services/converters.go | 11 +- internal/services/device_service.go | 7 +- internal/services/server_service.go | 1 + proto/Dockerfile | 5 +- proto/proto/devices.pb.go | 196 +------------------------ proto/proto/devices_grpc.pb.go | 216 ++++++++++++++++++++++++++++ proto/proto/server.pb.go | 86 +---------- proto/proto/server_grpc.pb.go | 105 ++++++++++++++ 11 files changed, 343 insertions(+), 297 deletions(-) create mode 100644 proto/proto/devices_grpc.pb.go create mode 100644 proto/proto/server_grpc.pb.go diff --git a/codegen.sh b/codegen.sh index 77066bb2..5ee63b2f 100755 --- a/codegen.sh +++ b/codegen.sh @@ -8,6 +8,6 @@ mkdir -p "$OUT_DIR" || true protoc \ -I proto/ \ - proto/*.proto \ - --go_opt=paths=source_relative \ - --go_out="plugins=grpc:$OUT_DIR" + --go_out="$OUT_DIR" --go_opt=paths=source_relative \ + --go-grpc_out="$OUT_DIR" --go-grpc_opt=paths=source_relative \ + proto/*.proto diff --git a/go.mod b/go.mod index 2e568280..a9e21665 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/docker/libnetwork v0.8.0-dev.2.0.20200217033114-6659f7f4d8c1 github.com/freifunkMUC/pg-events v0.4.0 github.com/freifunkMUC/wg-embed v0.7.0 - github.com/golang/protobuf v1.5.2 github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 github.com/gorilla/sessions v1.2.1 @@ -26,7 +25,7 @@ require ( golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f golang.zx2c4.com/wireguard/wgctrl v0.0.0-20211207222515-92d582e4e166 google.golang.org/grpc v1.45.0 - google.golang.org/protobuf v1.27.1 + google.golang.org/protobuf v1.28.0 gopkg.in/Knetic/govaluate.v2 v2.3.0 gopkg.in/alecthomas/kingpin.v2 v2.2.6 gopkg.in/yaml.v2 v2.4.0 @@ -41,6 +40,7 @@ require ( github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect github.com/docker/docker v20.10.8+incompatible // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect + github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-cmp v0.5.6 // indirect github.com/gorilla/securecookie v1.1.1 // indirect github.com/gorilla/websocket v1.4.2 // indirect diff --git a/go.sum b/go.sum index ed657a74..4ece51ea 100644 --- a/go.sum +++ b/go.sum @@ -899,8 +899,9 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/Knetic/govaluate.v2 v2.3.0 h1:naJVc9CZlWA8rC8f5mvECJD7jreTrn7FvGXjBthkHJQ= gopkg.in/Knetic/govaluate.v2 v2.3.0/go.mod h1:NW0gr10J8s7aNghEg6uhdxiEaBvc0+8VgJjVViHUKp4= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= diff --git a/internal/services/converters.go b/internal/services/converters.go index 620c4cec..bf9567ba 100644 --- a/internal/services/converters.go +++ b/internal/services/converters.go @@ -3,17 +3,16 @@ package services import ( "time" - "github.com/golang/protobuf/ptypes/timestamp" - "github.com/golang/protobuf/ptypes/wrappers" "github.com/sirupsen/logrus" "google.golang.org/protobuf/types/known/timestamppb" + "google.golang.org/protobuf/types/known/wrapperspb" ) -func TimestampToTime(value *timestamp.Timestamp) time.Time { +func TimestampToTime(value *timestamppb.Timestamp) time.Time { return time.Unix(value.Seconds, int64(value.Nanos)) } -func TimeToTimestamp(value *time.Time) *timestamp.Timestamp { +func TimeToTimestamp(value *time.Time) *timestamppb.Timestamp { if value == nil { return nil } @@ -25,9 +24,9 @@ func TimeToTimestamp(value *time.Time) *timestamp.Timestamp { return t } -func stringValue(value *string) *wrappers.StringValue { +func stringValue(value *string) *wrapperspb.StringValue { if value != nil { - return &wrappers.StringValue{ + return &wrapperspb.StringValue{ Value: *value, } } diff --git a/internal/services/device_service.go b/internal/services/device_service.go index 3c2d3e1e..69353451 100644 --- a/internal/services/device_service.go +++ b/internal/services/device_service.go @@ -8,13 +8,14 @@ import ( "github.com/freifunkMUC/wg-access-server/pkg/authnz/authsession" "github.com/freifunkMUC/wg-access-server/proto/proto" - "github.com/golang/protobuf/ptypes/empty" "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/emptypb" ) type DeviceService struct { + proto.UnimplementedDevicesServer DeviceManager *devices.DeviceManager } @@ -49,7 +50,7 @@ func (d *DeviceService) ListDevices(ctx context.Context, req *proto.ListDevicesR }, nil } -func (d *DeviceService) DeleteDevice(ctx context.Context, req *proto.DeleteDeviceReq) (*empty.Empty, error) { +func (d *DeviceService) DeleteDevice(ctx context.Context, req *proto.DeleteDeviceReq) (*emptypb.Empty, error) { user, err := authsession.CurrentUser(ctx) if err != nil { return nil, status.Errorf(codes.PermissionDenied, "not authenticated") @@ -70,7 +71,7 @@ func (d *DeviceService) DeleteDevice(ctx context.Context, req *proto.DeleteDevic return nil, status.Errorf(codes.Internal, "failed to delete device") } - return &empty.Empty{}, nil + return &emptypb.Empty{}, nil } func (d *DeviceService) ListAllDevices(ctx context.Context, req *proto.ListAllDevicesReq) (*proto.ListAllDevicesRes, error) { diff --git a/internal/services/server_service.go b/internal/services/server_service.go index 8aed624e..64329e10 100644 --- a/internal/services/server_service.go +++ b/internal/services/server_service.go @@ -16,6 +16,7 @@ import ( ) type ServerService struct { + proto.UnimplementedServerServer Config *config.AppConfig Wg wgembed.WireGuardInterface } diff --git a/proto/Dockerfile b/proto/Dockerfile index a86bd26d..7a08ce8e 100644 --- a/proto/Dockerfile +++ b/proto/Dockerfile @@ -8,10 +8,11 @@ RUN npm ci --no-audit --prefer-offline # Mount ./website/src/sdk to /code/src/sdk CMD ["npm", "run", "codegen"] -FROM golang:1.17-alpine as proto-go +FROM golang:1.18-alpine as proto-go RUN apk add --no-cache protobuf protobuf-dev WORKDIR /code -RUN go install github.com/golang/protobuf/protoc-gen-go@v1.5.2 +RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0 +RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.0 # Mount ./proto to /code/proto COPY ./codegen.sh ./ CMD ["./codegen.sh"] diff --git a/proto/proto/devices.pb.go b/proto/proto/devices.pb.go index 70950db1..e9a03238 100644 --- a/proto/proto/devices.pb.go +++ b/proto/proto/devices.pb.go @@ -1,16 +1,12 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 +// protoc-gen-go v1.28.0 // protoc v3.18.1 // source: devices.proto package proto import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" emptypb "google.golang.org/protobuf/types/known/emptypb" @@ -692,193 +688,3 @@ func file_devices_proto_init() { file_devices_proto_goTypes = nil file_devices_proto_depIdxs = nil } - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConnInterface - -// 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 - -// DevicesClient is the client API for Devices service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type DevicesClient interface { - AddDevice(ctx context.Context, in *AddDeviceReq, opts ...grpc.CallOption) (*Device, error) - ListDevices(ctx context.Context, in *ListDevicesReq, opts ...grpc.CallOption) (*ListDevicesRes, error) - DeleteDevice(ctx context.Context, in *DeleteDeviceReq, opts ...grpc.CallOption) (*emptypb.Empty, error) - // admin only - ListAllDevices(ctx context.Context, in *ListAllDevicesReq, opts ...grpc.CallOption) (*ListAllDevicesRes, error) -} - -type devicesClient struct { - cc grpc.ClientConnInterface -} - -func NewDevicesClient(cc grpc.ClientConnInterface) DevicesClient { - return &devicesClient{cc} -} - -func (c *devicesClient) AddDevice(ctx context.Context, in *AddDeviceReq, opts ...grpc.CallOption) (*Device, error) { - out := new(Device) - err := c.cc.Invoke(ctx, "/proto.Devices/AddDevice", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *devicesClient) ListDevices(ctx context.Context, in *ListDevicesReq, opts ...grpc.CallOption) (*ListDevicesRes, error) { - out := new(ListDevicesRes) - err := c.cc.Invoke(ctx, "/proto.Devices/ListDevices", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *devicesClient) DeleteDevice(ctx context.Context, in *DeleteDeviceReq, opts ...grpc.CallOption) (*emptypb.Empty, error) { - out := new(emptypb.Empty) - err := c.cc.Invoke(ctx, "/proto.Devices/DeleteDevice", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *devicesClient) ListAllDevices(ctx context.Context, in *ListAllDevicesReq, opts ...grpc.CallOption) (*ListAllDevicesRes, error) { - out := new(ListAllDevicesRes) - err := c.cc.Invoke(ctx, "/proto.Devices/ListAllDevices", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// DevicesServer is the server API for Devices service. -type DevicesServer interface { - AddDevice(context.Context, *AddDeviceReq) (*Device, error) - ListDevices(context.Context, *ListDevicesReq) (*ListDevicesRes, error) - DeleteDevice(context.Context, *DeleteDeviceReq) (*emptypb.Empty, error) - // admin only - ListAllDevices(context.Context, *ListAllDevicesReq) (*ListAllDevicesRes, error) -} - -// UnimplementedDevicesServer can be embedded to have forward compatible implementations. -type UnimplementedDevicesServer struct { -} - -func (*UnimplementedDevicesServer) AddDevice(context.Context, *AddDeviceReq) (*Device, error) { - return nil, status.Errorf(codes.Unimplemented, "method AddDevice not implemented") -} -func (*UnimplementedDevicesServer) ListDevices(context.Context, *ListDevicesReq) (*ListDevicesRes, error) { - return nil, status.Errorf(codes.Unimplemented, "method ListDevices not implemented") -} -func (*UnimplementedDevicesServer) DeleteDevice(context.Context, *DeleteDeviceReq) (*emptypb.Empty, error) { - return nil, status.Errorf(codes.Unimplemented, "method DeleteDevice not implemented") -} -func (*UnimplementedDevicesServer) ListAllDevices(context.Context, *ListAllDevicesReq) (*ListAllDevicesRes, error) { - return nil, status.Errorf(codes.Unimplemented, "method ListAllDevices not implemented") -} - -func RegisterDevicesServer(s *grpc.Server, srv DevicesServer) { - s.RegisterService(&_Devices_serviceDesc, srv) -} - -func _Devices_AddDevice_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AddDeviceReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(DevicesServer).AddDevice(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/proto.Devices/AddDevice", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(DevicesServer).AddDevice(ctx, req.(*AddDeviceReq)) - } - return interceptor(ctx, in, info, handler) -} - -func _Devices_ListDevices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListDevicesReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(DevicesServer).ListDevices(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/proto.Devices/ListDevices", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(DevicesServer).ListDevices(ctx, req.(*ListDevicesReq)) - } - return interceptor(ctx, in, info, handler) -} - -func _Devices_DeleteDevice_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DeleteDeviceReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(DevicesServer).DeleteDevice(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/proto.Devices/DeleteDevice", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(DevicesServer).DeleteDevice(ctx, req.(*DeleteDeviceReq)) - } - return interceptor(ctx, in, info, handler) -} - -func _Devices_ListAllDevices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListAllDevicesReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(DevicesServer).ListAllDevices(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/proto.Devices/ListAllDevices", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(DevicesServer).ListAllDevices(ctx, req.(*ListAllDevicesReq)) - } - return interceptor(ctx, in, info, handler) -} - -var _Devices_serviceDesc = grpc.ServiceDesc{ - ServiceName: "proto.Devices", - HandlerType: (*DevicesServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "AddDevice", - Handler: _Devices_AddDevice_Handler, - }, - { - MethodName: "ListDevices", - Handler: _Devices_ListDevices_Handler, - }, - { - MethodName: "DeleteDevice", - Handler: _Devices_DeleteDevice_Handler, - }, - { - MethodName: "ListAllDevices", - Handler: _Devices_ListAllDevices_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "devices.proto", -} diff --git a/proto/proto/devices_grpc.pb.go b/proto/proto/devices_grpc.pb.go new file mode 100644 index 00000000..a53e729d --- /dev/null +++ b/proto/proto/devices_grpc.pb.go @@ -0,0 +1,216 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.18.1 +// source: devices.proto + +package proto + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// 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 + +// DevicesClient is the client API for Devices 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 DevicesClient interface { + AddDevice(ctx context.Context, in *AddDeviceReq, opts ...grpc.CallOption) (*Device, error) + ListDevices(ctx context.Context, in *ListDevicesReq, opts ...grpc.CallOption) (*ListDevicesRes, error) + DeleteDevice(ctx context.Context, in *DeleteDeviceReq, opts ...grpc.CallOption) (*emptypb.Empty, error) + // admin only + ListAllDevices(ctx context.Context, in *ListAllDevicesReq, opts ...grpc.CallOption) (*ListAllDevicesRes, error) +} + +type devicesClient struct { + cc grpc.ClientConnInterface +} + +func NewDevicesClient(cc grpc.ClientConnInterface) DevicesClient { + return &devicesClient{cc} +} + +func (c *devicesClient) AddDevice(ctx context.Context, in *AddDeviceReq, opts ...grpc.CallOption) (*Device, error) { + out := new(Device) + err := c.cc.Invoke(ctx, "/proto.Devices/AddDevice", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *devicesClient) ListDevices(ctx context.Context, in *ListDevicesReq, opts ...grpc.CallOption) (*ListDevicesRes, error) { + out := new(ListDevicesRes) + err := c.cc.Invoke(ctx, "/proto.Devices/ListDevices", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *devicesClient) DeleteDevice(ctx context.Context, in *DeleteDeviceReq, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, "/proto.Devices/DeleteDevice", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *devicesClient) ListAllDevices(ctx context.Context, in *ListAllDevicesReq, opts ...grpc.CallOption) (*ListAllDevicesRes, error) { + out := new(ListAllDevicesRes) + err := c.cc.Invoke(ctx, "/proto.Devices/ListAllDevices", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// DevicesServer is the server API for Devices service. +// All implementations must embed UnimplementedDevicesServer +// for forward compatibility +type DevicesServer interface { + AddDevice(context.Context, *AddDeviceReq) (*Device, error) + ListDevices(context.Context, *ListDevicesReq) (*ListDevicesRes, error) + DeleteDevice(context.Context, *DeleteDeviceReq) (*emptypb.Empty, error) + // admin only + ListAllDevices(context.Context, *ListAllDevicesReq) (*ListAllDevicesRes, error) + mustEmbedUnimplementedDevicesServer() +} + +// UnimplementedDevicesServer must be embedded to have forward compatible implementations. +type UnimplementedDevicesServer struct { +} + +func (UnimplementedDevicesServer) AddDevice(context.Context, *AddDeviceReq) (*Device, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddDevice not implemented") +} +func (UnimplementedDevicesServer) ListDevices(context.Context, *ListDevicesReq) (*ListDevicesRes, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListDevices not implemented") +} +func (UnimplementedDevicesServer) DeleteDevice(context.Context, *DeleteDeviceReq) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method DeleteDevice not implemented") +} +func (UnimplementedDevicesServer) ListAllDevices(context.Context, *ListAllDevicesReq) (*ListAllDevicesRes, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListAllDevices not implemented") +} +func (UnimplementedDevicesServer) mustEmbedUnimplementedDevicesServer() {} + +// UnsafeDevicesServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to DevicesServer will +// result in compilation errors. +type UnsafeDevicesServer interface { + mustEmbedUnimplementedDevicesServer() +} + +func RegisterDevicesServer(s grpc.ServiceRegistrar, srv DevicesServer) { + s.RegisterService(&Devices_ServiceDesc, srv) +} + +func _Devices_AddDevice_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AddDeviceReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DevicesServer).AddDevice(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Devices/AddDevice", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DevicesServer).AddDevice(ctx, req.(*AddDeviceReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Devices_ListDevices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListDevicesReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DevicesServer).ListDevices(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Devices/ListDevices", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DevicesServer).ListDevices(ctx, req.(*ListDevicesReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Devices_DeleteDevice_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteDeviceReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DevicesServer).DeleteDevice(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Devices/DeleteDevice", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DevicesServer).DeleteDevice(ctx, req.(*DeleteDeviceReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Devices_ListAllDevices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListAllDevicesReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DevicesServer).ListAllDevices(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Devices/ListAllDevices", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DevicesServer).ListAllDevices(ctx, req.(*ListAllDevicesReq)) + } + return interceptor(ctx, in, info, handler) +} + +// Devices_ServiceDesc is the grpc.ServiceDesc for Devices service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Devices_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "proto.Devices", + HandlerType: (*DevicesServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "AddDevice", + Handler: _Devices_AddDevice_Handler, + }, + { + MethodName: "ListDevices", + Handler: _Devices_ListDevices_Handler, + }, + { + MethodName: "DeleteDevice", + Handler: _Devices_DeleteDevice_Handler, + }, + { + MethodName: "ListAllDevices", + Handler: _Devices_ListAllDevices_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "devices.proto", +} diff --git a/proto/proto/server.pb.go b/proto/proto/server.pb.go index e5e67a4a..31a95ecc 100644 --- a/proto/proto/server.pb.go +++ b/proto/proto/server.pb.go @@ -1,16 +1,12 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 +// protoc-gen-go v1.28.0 // protoc v3.18.1 // source: server.proto package proto import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" wrapperspb "google.golang.org/protobuf/types/known/wrapperspb" @@ -289,83 +285,3 @@ func file_server_proto_init() { file_server_proto_goTypes = nil file_server_proto_depIdxs = nil } - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConnInterface - -// 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 - -// ServerClient is the client API for Server service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type ServerClient interface { - Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*InfoRes, error) -} - -type serverClient struct { - cc grpc.ClientConnInterface -} - -func NewServerClient(cc grpc.ClientConnInterface) ServerClient { - return &serverClient{cc} -} - -func (c *serverClient) Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*InfoRes, error) { - out := new(InfoRes) - err := c.cc.Invoke(ctx, "/proto.Server/Info", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// ServerServer is the server API for Server service. -type ServerServer interface { - Info(context.Context, *InfoReq) (*InfoRes, error) -} - -// UnimplementedServerServer can be embedded to have forward compatible implementations. -type UnimplementedServerServer struct { -} - -func (*UnimplementedServerServer) Info(context.Context, *InfoReq) (*InfoRes, error) { - return nil, status.Errorf(codes.Unimplemented, "method Info not implemented") -} - -func RegisterServerServer(s *grpc.Server, srv ServerServer) { - s.RegisterService(&_Server_serviceDesc, srv) -} - -func _Server_Info_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(InfoReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ServerServer).Info(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/proto.Server/Info", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ServerServer).Info(ctx, req.(*InfoReq)) - } - return interceptor(ctx, in, info, handler) -} - -var _Server_serviceDesc = grpc.ServiceDesc{ - ServiceName: "proto.Server", - HandlerType: (*ServerServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Info", - Handler: _Server_Info_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "server.proto", -} diff --git a/proto/proto/server_grpc.pb.go b/proto/proto/server_grpc.pb.go new file mode 100644 index 00000000..a116dcfe --- /dev/null +++ b/proto/proto/server_grpc.pb.go @@ -0,0 +1,105 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.18.1 +// source: server.proto + +package proto + +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 + +// ServerClient is the client API for Server 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 ServerClient interface { + Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*InfoRes, error) +} + +type serverClient struct { + cc grpc.ClientConnInterface +} + +func NewServerClient(cc grpc.ClientConnInterface) ServerClient { + return &serverClient{cc} +} + +func (c *serverClient) Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*InfoRes, error) { + out := new(InfoRes) + err := c.cc.Invoke(ctx, "/proto.Server/Info", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ServerServer is the server API for Server service. +// All implementations must embed UnimplementedServerServer +// for forward compatibility +type ServerServer interface { + Info(context.Context, *InfoReq) (*InfoRes, error) + mustEmbedUnimplementedServerServer() +} + +// UnimplementedServerServer must be embedded to have forward compatible implementations. +type UnimplementedServerServer struct { +} + +func (UnimplementedServerServer) Info(context.Context, *InfoReq) (*InfoRes, error) { + return nil, status.Errorf(codes.Unimplemented, "method Info not implemented") +} +func (UnimplementedServerServer) mustEmbedUnimplementedServerServer() {} + +// UnsafeServerServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ServerServer will +// result in compilation errors. +type UnsafeServerServer interface { + mustEmbedUnimplementedServerServer() +} + +func RegisterServerServer(s grpc.ServiceRegistrar, srv ServerServer) { + s.RegisterService(&Server_ServiceDesc, srv) +} + +func _Server_Info_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(InfoReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServerServer).Info(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/proto.Server/Info", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServerServer).Info(ctx, req.(*InfoReq)) + } + return interceptor(ctx, in, info, handler) +} + +// Server_ServiceDesc is the grpc.ServiceDesc for Server service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Server_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "proto.Server", + HandlerType: (*ServerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Info", + Handler: _Server_Info_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "server.proto", +}