From d5c23df2126b863574f172dbf37a475dbc358343 Mon Sep 17 00:00:00 2001 From: yingchaojie Date: Tue, 23 Aug 2022 09:32:40 +0800 Subject: [PATCH] v1.5.1: update --- service/mqttkit/mqtt.go | 8 ++++++-- service/storagekit/localStorage.go | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/service/mqttkit/mqtt.go b/service/mqttkit/mqtt.go index c7d102c..06d8e6b 100644 --- a/service/mqttkit/mqtt.go +++ b/service/mqttkit/mqtt.go @@ -28,7 +28,7 @@ func New() *MQTT.Client { panic(exception.New("请填写broker")) } opts.AddBroker(configkit.GetStringD(configkey.MQTTBroker)) - opts.SetKeepAlive(time.Duration(1) * time.Minute) + opts.SetKeepAlive(time.Duration(10) * time.Second) opts.SetAutoReconnect(true) opts.SetConnectRetry(true) opts.SetConnectRetryInterval(time.Duration(5) * time.Second) @@ -83,10 +83,14 @@ func Publish(topic string, qos byte, retained bool, payload any) error { New() } token := client.Publish(topic, qos, retained, payload) - token.Wait() + token.WaitTimeout(time.Duration(1) * time.Minute) if token.Error() != nil { logkit.Error(token.Error().Error()) return token.Error() } return nil } + +func GetClient() MQTT.Client { + return client +} diff --git a/service/storagekit/localStorage.go b/service/storagekit/localStorage.go index d0db74b..5a26604 100644 --- a/service/storagekit/localStorage.go +++ b/service/storagekit/localStorage.go @@ -29,6 +29,12 @@ func SaveBytesInHome(data []byte, path string) { _ = filekit.WriteFile(path, data) } +func SaveBytesAppendInHome(data []byte, path string) { + path = GetFullPath(path) + _ = filekit.CheckFilePath(path) + _ = filekit.WriteFileAppend(path, data) +} + func GetInHome(path string) []byte { path = GetFullPath(path) //file,err := os.OpenFile(path, os.O_RDONLY, 644)