fix dead code, typo, and minor bugs in main.go, process.go and index.go (#6167)

Fixes several small issues found during code review:
- fix(xray): return explicit nil instead of stale err in getLogPath
- fix(xray): remove duplicate doc comment on GetErrorLogPath
- refactor: remove unreachable return after log.Fatalf (×4)
- fix(cli): add missing newline to listen IP success message
- fix(cli): typo "form" → "from" in migrate help text
- refactor: simplify var+assign to short declaration for server/subServer
- fix(controller): return error from getTwoFactorEnable instead of swallowing it
This commit is contained in:
Isuru Sampath
2026-07-31 21:57:46 +05:30
committed by GitHub
parent 264f61eb90
commit 31c1eed5dc
3 changed files with 6 additions and 15 deletions

View File

@@ -163,7 +163,5 @@ func (a *IndexController) csrfToken(c *gin.Context) {
// getTwoFactorEnable retrieves the current status of two-factor authentication.
func (a *IndexController) getTwoFactorEnable(c *gin.Context) {
status, err := a.settingService.GetTwoFactorEnable()
if err == nil {
jsonObj(c, status, nil)
}
jsonObj(c, status, err)
}

View File

@@ -85,7 +85,7 @@ func getLogPath(key string) (string, error) {
return logPath, nil
}
}
return "", err
return "", nil
}
// GetAccessLogPath reads the Xray config and returns the access log file path.
@@ -93,7 +93,6 @@ func GetAccessLogPath() (string, error) {
return getLogPath("access")
}
// GetErrorLogPath reads the Xray config and returns the error log file path.
// GetErrorLogPath reads the Xray config and returns the error log file path.
func GetErrorLogPath() (string, error) {
return getLogPath("error")

14
main.go
View File

@@ -71,24 +71,20 @@ func runWebServer() {
log.Fatalf("Error initializing database: %v", err)
}
var server *web.Server
server = web.NewServer()
server := web.NewServer()
global.SetWebServer(server)
err = server.Start()
if err != nil {
log.Fatalf("Error starting web server: %v", err)
return
}
var subServer *sub.Server
sub.SetDistFS(web.EmbeddedDist())
service.RegisterSubLinkProvider(sub.NewLinkProvider())
subServer = sub.NewServer()
subServer := sub.NewServer()
global.SetSubServer(subServer)
err = subServer.Start()
if err != nil {
log.Fatalf("Error starting sub server: %v", err)
return
}
sigCh := make(chan os.Signal, 8)
@@ -142,7 +138,6 @@ func runWebServer() {
err = server.StartPanelOnly()
if err != nil {
log.Fatalf("Error restarting web server: %v", err)
return
}
log.Println("Web server restarted successfully.")
@@ -152,7 +147,6 @@ func runWebServer() {
err = subServer.Start()
if err != nil {
log.Fatalf("Error restarting sub server: %v", err)
return
}
log.Println("Sub server restarted successfully.")
case sys.SIGUSR1:
@@ -360,7 +354,7 @@ func updateSetting(port int, username string, password string, webBasePath strin
if err != nil {
fmt.Println("Failed to set listen IP:", err)
} else {
fmt.Printf("listen %v set successfully", listenIP)
fmt.Printf("listen %v set successfully\n", listenIP)
}
}
@@ -579,7 +573,7 @@ func main() {
fmt.Println()
fmt.Println("Commands:")
fmt.Println(" run run web panel")
fmt.Println(" migrate migrate form other/old x-ui")
fmt.Println(" migrate migrate from other/old x-ui")
fmt.Println(" migrate-db SQLite <-> .dump (--dump/--restore) or copy into PostgreSQL (--dsn)")
fmt.Println(" setting set settings")
}