From 74abf6e034205c9a3b29ed4a9b5d2880335e656c Mon Sep 17 00:00:00 2001 From: link Date: Mon, 6 Feb 2023 09:10:04 +0000 Subject: [PATCH 1/2] Remove client judgment --- main.go | 9 +-------- service/notify.go | 6 +----- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index ed1a83cb3..fe7bc9859 100644 --- a/main.go +++ b/main.go @@ -116,14 +116,7 @@ func main() { // every day execution err := cron2.AddFunc("0/5 * * * * *", func() { - if service.ClientCount > 0 { - // route.SendNetINfoBySocket() - // route.SendCPUBySocket() - // route.SendMemBySocket() - // route.SendDiskBySocket() - // route.SendUSBBySocket() - route.SendAllHardwareStatusBySocket() - } + route.SendAllHardwareStatusBySocket() }) if err != nil { fmt.Println(err) diff --git a/service/notify.go b/service/notify.go index 7276c45d6..8df6e5158 100644 --- a/service/notify.go +++ b/service/notify.go @@ -21,11 +21,6 @@ import ( "gorm.io/gorm" ) -var ( - //NotifyMsg chan notify.Message - ClientCount int -) - type NotifyServer interface { GetLog(id string) model.AppNotify AddLog(log model.AppNotify) @@ -64,6 +59,7 @@ func (i *notifyServer) SendNotify(name string, message map[string]interface{}) { response, err := MyService.MessageBus().PublishEventWithResponse(context.Background(), common.SERVICENAME, name, msg) if err != nil { logger.Error("failed to publish event to message bus", zap.Error(err), zap.Any("event", msg)) + return } if response.StatusCode() != http.StatusOK { logger.Error("failed to publish event to message bus", zap.String("status", response.Status()), zap.Any("response", response)) From f7c9be5fb2fbe3315a7f01219fd645a118d78856 Mon Sep 17 00:00:00 2001 From: link Date: Mon, 6 Feb 2023 09:43:08 +0000 Subject: [PATCH 2/2] Return of error when modifying mount --- go.mod | 2 -- go.sum | 4 ---- pkg/utils/httper/drive.go | 5 +++++ service/storage.go | 15 +++++++++++---- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 81e48bbfe..589de413d 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,6 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 github.com/robfig/cron v1.2.0 - github.com/samber/lo v1.37.0 github.com/satori/go.uuid v1.2.0 github.com/shirou/gopsutil/v3 v3.22.11 github.com/sirupsen/logrus v1.9.0 @@ -109,7 +108,6 @@ require ( github.com/yusufpapurcu/wmi v1.2.2 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect - golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect golang.org/x/net v0.5.0 // indirect golang.org/x/sys v0.4.0 // indirect diff --git a/go.sum b/go.sum index a9e17e2dd..1aaadd88a 100644 --- a/go.sum +++ b/go.sum @@ -232,8 +232,6 @@ github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfm github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= -github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw= -github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA= github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/shirou/gopsutil/v3 v3.22.11 h1:kxsPKS+Eeo+VnEQ2XCaGJepeP6KY53QoRTETx3+1ndM= @@ -294,8 +292,6 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= -golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM= -golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= diff --git a/pkg/utils/httper/drive.go b/pkg/utils/httper/drive.go index 5693d28e8..cdf49e26c 100644 --- a/pkg/utils/httper/drive.go +++ b/pkg/utils/httper/drive.go @@ -7,7 +7,9 @@ import ( "net/http" "time" + "github.com/IceWhaleTech/CasaOS-Common/utils/logger" "github.com/go-resty/resty/v2" + "go.uber.org/zap" ) type MountList struct { @@ -82,6 +84,7 @@ func Mount(mountPoint string, fs string) error { if res.StatusCode() != 200 { return fmt.Errorf("mount failed") } + logger.Info("mount then", zap.Any("res", res.Body())) return nil } func Unmount(mountPoint string) error { @@ -94,6 +97,7 @@ func Unmount(mountPoint string) error { if res.StatusCode() != 200 { return fmt.Errorf("unmount failed") } + logger.Info("unmount then", zap.Any("res", res.Body())) return nil } @@ -111,6 +115,7 @@ func CreateConfig(data map[string]string, name, t string) error { if res.StatusCode() != 200 { return fmt.Errorf("create config failed") } + logger.Info("create config then", zap.Any("res", res.Body())) return nil } diff --git a/service/storage.go b/service/storage.go index cf347f186..01fd45ee8 100644 --- a/service/storage.go +++ b/service/storage.go @@ -3,8 +3,10 @@ package service import ( "io/ioutil" + "github.com/IceWhaleTech/CasaOS-Common/utils/logger" "github.com/IceWhaleTech/CasaOS/pkg/utils/file" "github.com/IceWhaleTech/CasaOS/pkg/utils/httper" + "go.uber.org/zap" ) type StorageService interface { @@ -23,8 +25,7 @@ type storageStruct struct { func (s *storageStruct) MountStorage(mountPoint, fs string) error { file.IsNotExistMkDir(mountPoint) - httper.Mount(mountPoint, fs) - return nil + return httper.Mount(mountPoint, fs) } func (s *storageStruct) UnmountStorage(mountPoint string) error { err := httper.Unmount(mountPoint) @@ -57,7 +58,7 @@ func (s *storageStruct) CheckAndMountByName(name string) error { } } if !isMount { - MyService.Storage().MountStorage(mountPoint, name+":") + return MyService.Storage().MountStorage(mountPoint, name+":") } return nil } @@ -66,10 +67,12 @@ func (s *storageStruct) CheckAndMountAll() error { if err != nil { return err } + logger.Info("when CheckAndMountAll storages", zap.Any("storages", storages)) section, err := httper.GetAllConfigName() if err != nil { return err } + logger.Info("when CheckAndMountAll section", zap.Any("section", section)) for _, v := range section.Remotes { currentRemote, _ := httper.GetConfigByName(v) mountPoint := currentRemote["mount_point"] @@ -84,7 +87,11 @@ func (s *storageStruct) CheckAndMountAll() error { } } if !isMount { - return MyService.Storage().MountStorage(mountPoint, v+":") + logger.Info("when CheckAndMountAll MountStorage", zap.String("mountPoint", mountPoint), zap.String("fs", v)) + err := MyService.Storage().MountStorage(mountPoint, v+":") + if err != nil { + logger.Error("when CheckAndMountAll then", zap.String("mountPoint", mountPoint), zap.String("fs", v), zap.Error(err)) + } } } return nil