Explorar o código

编写sshd远程运维模块的client代码

niujiuru hai 3 semanas
pai
achega
df487368fb
Modificáronse 3 ficheiros con 6 adicións e 0 borrados
  1. 1 0
      go.mod
  2. 2 0
      go.sum
  3. 3 0
      sshd/client/client.go

+ 1 - 0
go.mod

@@ -6,6 +6,7 @@ require (
 	github.com/alexflint/go-filemutex v1.3.0
 	github.com/beevik/ntp v1.5.0
 	github.com/eclipse/paho.mqtt.golang v1.5.1
+	github.com/google/uuid v1.6.0
 	github.com/jlaffaye/ftp v0.2.0
 	github.com/mattn/go-shellwords v1.0.12
 	github.com/sirupsen/logrus v1.9.3

+ 2 - 0
go.sum

@@ -7,6 +7,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/eclipse/paho.mqtt.golang v1.5.1 h1:/VSOv3oDLlpqR2Epjn1Q7b2bSTplJIeV2ISgCl2W7nE=
 github.com/eclipse/paho.mqtt.golang v1.5.1/go.mod h1:1/yJCneuyOoCOzKSsOTUc0AJfpsItBGWvYpBLimhArU=
+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
 github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
 github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=

+ 3 - 0
sshd/client/client.go

@@ -9,6 +9,7 @@ import (
 	"time"
 
 	mqtt "github.com/eclipse/paho.mqtt.golang"
+	"github.com/google/uuid"
 	"hnyfkj.com.cn/rtu/linux/baseapp"
 )
 
@@ -34,6 +35,7 @@ var (
 type MQTTCoupler struct {
 	broker, username, password string
 	client                     mqtt.Client
+	clientID                   string
 
 	imei     string // 设备唯一标识
 	subTopic string // 订阅应答主题:/yfkj/device/rpc/imei/ack
@@ -58,6 +60,7 @@ func init() {
 		broker:      CfgServers.MQTTSrv.Address,
 		username:    CfgServers.MQTTSrv.Username,
 		password:    CfgServers.MQTTSrv.Password,
+		clientID:    uuid.New().String(),
 		cwd:         "/",
 		ctx:         ctx,
 		cancel:      cancel,