Реализация device-control-service: gRPC + MQTT + Device Shadow в Redis
Добавлен gRPC-контракт proto/device_control (TurnOn/TurnOff/SetLevel), общий Go-модуль proto/ для переиспользования сгенерированного кода. device-control-service принимает команды по gRPC, обновляет desired_state в Redis и публикует их в MQTT; слушает devices/+/telemetry и devices/+/ack для отметки живости устройства и обновления reported_state; горутина health-check переводит устройство в offline по таймауту и публикует событие в RabbitMQ (device.status_changed) для будущего notification-service. Проверено сквозным тестом через docker compose: grpcurl TurnOn/SetLevel меняет desired_state и уходит в MQTT, mosquitto_pub с ack обновляет reported_state и статус, health-check автоматически переводит устройство в offline по истечении таймаута.
This commit is contained in:
@@ -0,0 +1,291 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc v7.35.1
|
||||
// source: device_control/device_control.proto
|
||||
|
||||
package device_control
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
unsafe "unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type TurnOnRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
DeviceId string `protobuf:"bytes,1,opt,name=device_id,json=deviceId,proto3" json:"device_id,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *TurnOnRequest) Reset() {
|
||||
*x = TurnOnRequest{}
|
||||
mi := &file_device_control_device_control_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *TurnOnRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*TurnOnRequest) ProtoMessage() {}
|
||||
|
||||
func (x *TurnOnRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_device_control_device_control_proto_msgTypes[0]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use TurnOnRequest.ProtoReflect.Descriptor instead.
|
||||
func (*TurnOnRequest) Descriptor() ([]byte, []int) {
|
||||
return file_device_control_device_control_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *TurnOnRequest) GetDeviceId() string {
|
||||
if x != nil {
|
||||
return x.DeviceId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type TurnOffRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
DeviceId string `protobuf:"bytes,1,opt,name=device_id,json=deviceId,proto3" json:"device_id,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *TurnOffRequest) Reset() {
|
||||
*x = TurnOffRequest{}
|
||||
mi := &file_device_control_device_control_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *TurnOffRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*TurnOffRequest) ProtoMessage() {}
|
||||
|
||||
func (x *TurnOffRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_device_control_device_control_proto_msgTypes[1]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use TurnOffRequest.ProtoReflect.Descriptor instead.
|
||||
func (*TurnOffRequest) Descriptor() ([]byte, []int) {
|
||||
return file_device_control_device_control_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *TurnOffRequest) GetDeviceId() string {
|
||||
if x != nil {
|
||||
return x.DeviceId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type SetLevelRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
DeviceId string `protobuf:"bytes,1,opt,name=device_id,json=deviceId,proto3" json:"device_id,omitempty"`
|
||||
Level float64 `protobuf:"fixed64,2,opt,name=level,proto3" json:"level,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *SetLevelRequest) Reset() {
|
||||
*x = SetLevelRequest{}
|
||||
mi := &file_device_control_device_control_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *SetLevelRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*SetLevelRequest) ProtoMessage() {}
|
||||
|
||||
func (x *SetLevelRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_device_control_device_control_proto_msgTypes[2]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use SetLevelRequest.ProtoReflect.Descriptor instead.
|
||||
func (*SetLevelRequest) Descriptor() ([]byte, []int) {
|
||||
return file_device_control_device_control_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *SetLevelRequest) GetDeviceId() string {
|
||||
if x != nil {
|
||||
return x.DeviceId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *SetLevelRequest) GetLevel() float64 {
|
||||
if x != nil {
|
||||
return x.Level
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type CommandResult struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
|
||||
Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *CommandResult) Reset() {
|
||||
*x = CommandResult{}
|
||||
mi := &file_device_control_device_control_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *CommandResult) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CommandResult) ProtoMessage() {}
|
||||
|
||||
func (x *CommandResult) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_device_control_device_control_proto_msgTypes[3]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use CommandResult.ProtoReflect.Descriptor instead.
|
||||
func (*CommandResult) Descriptor() ([]byte, []int) {
|
||||
return file_device_control_device_control_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *CommandResult) GetSuccess() bool {
|
||||
if x != nil {
|
||||
return x.Success
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *CommandResult) GetError() string {
|
||||
if x != nil {
|
||||
return x.Error
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_device_control_device_control_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_device_control_device_control_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"#device_control/device_control.proto\x12\x0edevice_control\",\n" +
|
||||
"\rTurnOnRequest\x12\x1b\n" +
|
||||
"\tdevice_id\x18\x01 \x01(\tR\bdeviceId\"-\n" +
|
||||
"\x0eTurnOffRequest\x12\x1b\n" +
|
||||
"\tdevice_id\x18\x01 \x01(\tR\bdeviceId\"D\n" +
|
||||
"\x0fSetLevelRequest\x12\x1b\n" +
|
||||
"\tdevice_id\x18\x01 \x01(\tR\bdeviceId\x12\x14\n" +
|
||||
"\x05level\x18\x02 \x01(\x01R\x05level\"?\n" +
|
||||
"\rCommandResult\x12\x18\n" +
|
||||
"\asuccess\x18\x01 \x01(\bR\asuccess\x12\x14\n" +
|
||||
"\x05error\x18\x02 \x01(\tR\x05error2\xed\x01\n" +
|
||||
"\rDeviceControl\x12F\n" +
|
||||
"\x06TurnOn\x12\x1d.device_control.TurnOnRequest\x1a\x1d.device_control.CommandResult\x12H\n" +
|
||||
"\aTurnOff\x12\x1e.device_control.TurnOffRequest\x1a\x1d.device_control.CommandResult\x12J\n" +
|
||||
"\bSetLevel\x12\x1f.device_control.SetLevelRequest\x1a\x1d.device_control.CommandResultB>Z<git.cactoz.su/cacto/home_automatization/proto/device_controlb\x06proto3"
|
||||
|
||||
var (
|
||||
file_device_control_device_control_proto_rawDescOnce sync.Once
|
||||
file_device_control_device_control_proto_rawDescData []byte
|
||||
)
|
||||
|
||||
func file_device_control_device_control_proto_rawDescGZIP() []byte {
|
||||
file_device_control_device_control_proto_rawDescOnce.Do(func() {
|
||||
file_device_control_device_control_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_device_control_device_control_proto_rawDesc), len(file_device_control_device_control_proto_rawDesc)))
|
||||
})
|
||||
return file_device_control_device_control_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_device_control_device_control_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
|
||||
var file_device_control_device_control_proto_goTypes = []any{
|
||||
(*TurnOnRequest)(nil), // 0: device_control.TurnOnRequest
|
||||
(*TurnOffRequest)(nil), // 1: device_control.TurnOffRequest
|
||||
(*SetLevelRequest)(nil), // 2: device_control.SetLevelRequest
|
||||
(*CommandResult)(nil), // 3: device_control.CommandResult
|
||||
}
|
||||
var file_device_control_device_control_proto_depIdxs = []int32{
|
||||
0, // 0: device_control.DeviceControl.TurnOn:input_type -> device_control.TurnOnRequest
|
||||
1, // 1: device_control.DeviceControl.TurnOff:input_type -> device_control.TurnOffRequest
|
||||
2, // 2: device_control.DeviceControl.SetLevel:input_type -> device_control.SetLevelRequest
|
||||
3, // 3: device_control.DeviceControl.TurnOn:output_type -> device_control.CommandResult
|
||||
3, // 4: device_control.DeviceControl.TurnOff:output_type -> device_control.CommandResult
|
||||
3, // 5: device_control.DeviceControl.SetLevel:output_type -> device_control.CommandResult
|
||||
3, // [3:6] is the sub-list for method output_type
|
||||
0, // [0:3] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_device_control_device_control_proto_init() }
|
||||
func file_device_control_device_control_proto_init() {
|
||||
if File_device_control_device_control_proto != nil {
|
||||
return
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_device_control_device_control_proto_rawDesc), len(file_device_control_device_control_proto_rawDesc)),
|
||||
NumEnums: 0,
|
||||
NumMessages: 4,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_device_control_device_control_proto_goTypes,
|
||||
DependencyIndexes: file_device_control_device_control_proto_depIdxs,
|
||||
MessageInfos: file_device_control_device_control_proto_msgTypes,
|
||||
}.Build()
|
||||
File_device_control_device_control_proto = out.File
|
||||
file_device_control_device_control_proto_goTypes = nil
|
||||
file_device_control_device_control_proto_depIdxs = nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package device_control;
|
||||
|
||||
option go_package = "git.cactoz.su/cacto/home_automatization/proto/device_control";
|
||||
|
||||
// DeviceControl is the synchronous entry point for issuing commands to a
|
||||
// device. It covers the generic actuator capabilities used across the
|
||||
// platform (device_types.capabilities: turn_on, turn_off, set_level) — no
|
||||
// zone- or device-type-specific methods. A call here updates the device's
|
||||
// desired state and dispatches the command over MQTT; it does not wait for
|
||||
// the device to confirm execution (see the Device Shadow pattern in
|
||||
// device-control-service's README).
|
||||
service DeviceControl {
|
||||
rpc TurnOn(TurnOnRequest) returns (CommandResult);
|
||||
rpc TurnOff(TurnOffRequest) returns (CommandResult);
|
||||
rpc SetLevel(SetLevelRequest) returns (CommandResult);
|
||||
}
|
||||
|
||||
message TurnOnRequest {
|
||||
string device_id = 1;
|
||||
}
|
||||
|
||||
message TurnOffRequest {
|
||||
string device_id = 1;
|
||||
}
|
||||
|
||||
message SetLevelRequest {
|
||||
string device_id = 1;
|
||||
double level = 2;
|
||||
}
|
||||
|
||||
message CommandResult {
|
||||
bool success = 1;
|
||||
string error = 2;
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.6.2
|
||||
// - protoc v7.35.1
|
||||
// source: device_control/device_control.proto
|
||||
|
||||
package device_control
|
||||
|
||||
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.64.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion9
|
||||
|
||||
const (
|
||||
DeviceControl_TurnOn_FullMethodName = "/device_control.DeviceControl/TurnOn"
|
||||
DeviceControl_TurnOff_FullMethodName = "/device_control.DeviceControl/TurnOff"
|
||||
DeviceControl_SetLevel_FullMethodName = "/device_control.DeviceControl/SetLevel"
|
||||
)
|
||||
|
||||
// DeviceControlClient is the client API for DeviceControl 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.
|
||||
//
|
||||
// DeviceControl is the synchronous entry point for issuing commands to a
|
||||
// device. It covers the generic actuator capabilities used across the
|
||||
// platform (device_types.capabilities: turn_on, turn_off, set_level) — no
|
||||
// zone- or device-type-specific methods. A call here updates the device's
|
||||
// desired state and dispatches the command over MQTT; it does not wait for
|
||||
// the device to confirm execution (see the Device Shadow pattern in
|
||||
// device-control-service's README).
|
||||
type DeviceControlClient interface {
|
||||
TurnOn(ctx context.Context, in *TurnOnRequest, opts ...grpc.CallOption) (*CommandResult, error)
|
||||
TurnOff(ctx context.Context, in *TurnOffRequest, opts ...grpc.CallOption) (*CommandResult, error)
|
||||
SetLevel(ctx context.Context, in *SetLevelRequest, opts ...grpc.CallOption) (*CommandResult, error)
|
||||
}
|
||||
|
||||
type deviceControlClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewDeviceControlClient(cc grpc.ClientConnInterface) DeviceControlClient {
|
||||
return &deviceControlClient{cc}
|
||||
}
|
||||
|
||||
func (c *deviceControlClient) TurnOn(ctx context.Context, in *TurnOnRequest, opts ...grpc.CallOption) (*CommandResult, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CommandResult)
|
||||
err := c.cc.Invoke(ctx, DeviceControl_TurnOn_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *deviceControlClient) TurnOff(ctx context.Context, in *TurnOffRequest, opts ...grpc.CallOption) (*CommandResult, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CommandResult)
|
||||
err := c.cc.Invoke(ctx, DeviceControl_TurnOff_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *deviceControlClient) SetLevel(ctx context.Context, in *SetLevelRequest, opts ...grpc.CallOption) (*CommandResult, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CommandResult)
|
||||
err := c.cc.Invoke(ctx, DeviceControl_SetLevel_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// DeviceControlServer is the server API for DeviceControl service.
|
||||
// All implementations must embed UnimplementedDeviceControlServer
|
||||
// for forward compatibility.
|
||||
//
|
||||
// DeviceControl is the synchronous entry point for issuing commands to a
|
||||
// device. It covers the generic actuator capabilities used across the
|
||||
// platform (device_types.capabilities: turn_on, turn_off, set_level) — no
|
||||
// zone- or device-type-specific methods. A call here updates the device's
|
||||
// desired state and dispatches the command over MQTT; it does not wait for
|
||||
// the device to confirm execution (see the Device Shadow pattern in
|
||||
// device-control-service's README).
|
||||
type DeviceControlServer interface {
|
||||
TurnOn(context.Context, *TurnOnRequest) (*CommandResult, error)
|
||||
TurnOff(context.Context, *TurnOffRequest) (*CommandResult, error)
|
||||
SetLevel(context.Context, *SetLevelRequest) (*CommandResult, error)
|
||||
mustEmbedUnimplementedDeviceControlServer()
|
||||
}
|
||||
|
||||
// UnimplementedDeviceControlServer must be embedded to have
|
||||
// forward compatible implementations.
|
||||
//
|
||||
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedDeviceControlServer struct{}
|
||||
|
||||
func (UnimplementedDeviceControlServer) TurnOn(context.Context, *TurnOnRequest) (*CommandResult, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method TurnOn not implemented")
|
||||
}
|
||||
func (UnimplementedDeviceControlServer) TurnOff(context.Context, *TurnOffRequest) (*CommandResult, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method TurnOff not implemented")
|
||||
}
|
||||
func (UnimplementedDeviceControlServer) SetLevel(context.Context, *SetLevelRequest) (*CommandResult, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method SetLevel not implemented")
|
||||
}
|
||||
func (UnimplementedDeviceControlServer) mustEmbedUnimplementedDeviceControlServer() {}
|
||||
func (UnimplementedDeviceControlServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeDeviceControlServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to DeviceControlServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeDeviceControlServer interface {
|
||||
mustEmbedUnimplementedDeviceControlServer()
|
||||
}
|
||||
|
||||
func RegisterDeviceControlServer(s grpc.ServiceRegistrar, srv DeviceControlServer) {
|
||||
// If the following call panics, it indicates UnimplementedDeviceControlServer was
|
||||
// embedded by pointer and is nil. This will cause panics if an
|
||||
// unimplemented method is ever invoked, so we test this at initialization
|
||||
// time to prevent it from happening at runtime later due to I/O.
|
||||
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||
t.testEmbeddedByValue()
|
||||
}
|
||||
s.RegisterService(&DeviceControl_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _DeviceControl_TurnOn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(TurnOnRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DeviceControlServer).TurnOn(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: DeviceControl_TurnOn_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DeviceControlServer).TurnOn(ctx, req.(*TurnOnRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _DeviceControl_TurnOff_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(TurnOffRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DeviceControlServer).TurnOff(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: DeviceControl_TurnOff_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DeviceControlServer).TurnOff(ctx, req.(*TurnOffRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _DeviceControl_SetLevel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SetLevelRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DeviceControlServer).SetLevel(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: DeviceControl_SetLevel_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DeviceControlServer).SetLevel(ctx, req.(*SetLevelRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// DeviceControl_ServiceDesc is the grpc.ServiceDesc for DeviceControl service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var DeviceControl_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "device_control.DeviceControl",
|
||||
HandlerType: (*DeviceControlServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "TurnOn",
|
||||
Handler: _DeviceControl_TurnOn_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "TurnOff",
|
||||
Handler: _DeviceControl_TurnOff_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "SetLevel",
|
||||
Handler: _DeviceControl_SetLevel_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "device_control/device_control.proto",
|
||||
}
|
||||
Reference in New Issue
Block a user