This commit is contained in:
tfl
2024-08-21 17:35:50 +08:00
parent 34ea7472b7
commit dd5b38b4e3
24 changed files with 328 additions and 133 deletions

35
pkg/device_rpc/rpc.go Normal file
View File

@@ -0,0 +1,35 @@
package devicerpc
import (
"errors"
"fmt"
"time"
"github.com/kakuilan/kgo"
)
type RpcPayload struct {
Method string `json:"method"`
Params any `json:"params"`
}
func (rp *RpcPayload) ToMap() map[string]any {
data, err := kgo.KConv.Struct2Map(rp, "")
if err != nil {
return nil
}
return data
}
// GetRequestResult 处理设备端请求服务端方法
func (rpc RpcPayload) GetRequestResult() (string, error) {
//TODO 此处处理设备的请求参数逻辑
//自己定义请求逻辑
if rpc.Params == "getCurrentTime" {
unix := time.Now().Unix()
msg := fmt.Sprintf("%d", unix)
return msg, nil
}
// 获取属性 ...
return "", errors.New("未获取到请求方法")
}