Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/app/service/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ func (u *SettingService) UpdateProxy(req dto.ProxyUpdate) error {
return err
}
go func() {
if err := xpack.Sync(constant.SyncSystemProxy); err != nil {
syncScope := constant.SyncSystemProxy
if req.WithDockerRestart {
syncScope = constant.SyncSystemProxyWithRestartDocker
}
if err := xpack.Sync(syncScope); err != nil {
global.LOG.Errorf("sync proxy to node failed, err: %v", err)
}
}()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code looks mostly clean but has a few improvements and clarifications that can be made for better readability, maintainability, and robustness:

  1. Variable Declaration: It would be more Pythonic to declare s.syncScope directly within the function scope instead of declaring it outside and then assigning it inside the goroutine.

  2. Function Scope: The syncScope variable should not need to be declared globally. Keeping it local to where we use it ensures better encapsulation and reduces unnecessary pollution of global names.

  3. Comments: Adding comments explaining why specific choices are made can help future readers understand the logic behind these lines.

Here is the revised version of the code with these suggestions:

@@ -212,8 +213,10 @@ func (u *SettingService) UpdateProxy(req dto.ProxyUpdate) error {
 	}

 	go func() {
-		if syncScope := constant.SyncSystemProxy; err := xpack.Sync(syncScope); err != nil {
+		var syncScope string
+		switch {
+		case req.WithDockerRestart:
+			syncScope = constant.SyncSystemProxyWithRestartDocker
+		default:
+			syncScope = constant.SyncSystemProxy
 		}
 		if err := xpack.Sync(syncScope); err != nil {
 			global.LOG.Errorf("sync proxy to node failed, err: %v", err)
 		}
@@ -224,13 +227,17 @@ go func() {

These changes make the code cleaner and easier to follow, while still maintaining its functionality.

Expand Down
13 changes: 7 additions & 6 deletions core/constant/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ const (
)

const (
SyncSystemProxy = "SyncSystemProxy"
SyncScripts = "SyncScripts"
SyncBackupAccounts = "SyncBackupAccounts"
SyncAlertSetting = "SyncAlertSetting"
SyncCustomApp = "SyncCustomApp"
SyncLanguage = "SyncLanguage"
SyncSystemProxy = "SyncSystemProxy"
SyncScripts = "SyncScripts"
SyncBackupAccounts = "SyncBackupAccounts"
SyncAlertSetting = "SyncAlertSetting"
SyncCustomApp = "SyncCustomApp"
SyncLanguage = "SyncLanguage"
SyncSystemProxyWithRestartDocker = "SyncSystemProxyWithRestartDocker"
)

var WebUrlMap = map[string]struct{}{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code snippet appears to be defining constants and a mapping within several Go files. There are minor style changes and additions made compared to the original version:

  • Replaced tabs with spaces for better readability.
  • Added a new constant SyncSystemProxyWithRestartDocker without modifications.

There are no significant errors or issues in this particular part of the file. However, it's always beneficial to ensure consistency across the entire codebase if you're working on multiple files at once.

Expand Down
Loading