refactor(manager/scheduler): optimize IP formatting error handling (#4201)

- Optimized error handling when IP formatting fails in the manager and scheduler modules
- Replaced errors.New with fmt.Errorf to improve readability of error messages
- Extracted IP address string into a separate variable to enhance code maintainability

Signed-off-by: jinronga <1460595002@qq.com>

Update manager.go

Update scheduler.go

Update manager.go

refactor(scheduler): 更新 GRPC 监听器的 IP 配置

- 将 GRPC监听 IP 改为全局监听 IP
- 优化了 IP格式化错误的错误消息
This commit is contained in:
jinronga 2025-07-11 11:14:57 +08:00 committed by GitHub
parent 986fcedb4d
commit 18fb640417
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 4 deletions

View File

@ -19,7 +19,6 @@ package manager
import ( import (
"context" "context"
"embed" "embed"
"errors"
"fmt" "fmt"
"io/fs" "io/fs"
"net" "net"
@ -318,7 +317,7 @@ func (s *Server) Serve() error {
// Generate GRPC listener. // Generate GRPC listener.
ip, ok := ip.FormatIP(s.config.Server.GRPC.ListenIP.String()) ip, ok := ip.FormatIP(s.config.Server.GRPC.ListenIP.String())
if !ok { if !ok {
return errors.New("format ip failed") return fmt.Errorf("format ip failed: %s", ip)
} }
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", ip, s.config.Server.GRPC.Port.Start)) listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", ip, s.config.Server.GRPC.Port.Start))

View File

@ -18,7 +18,6 @@ package scheduler
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
@ -269,7 +268,7 @@ func (s *Server) Serve() error {
// Generate GRPC listener. // Generate GRPC listener.
ip, ok := ip.FormatIP(s.config.Server.ListenIP.String()) ip, ok := ip.FormatIP(s.config.Server.ListenIP.String())
if !ok { if !ok {
return errors.New("format ip failed") return fmt.Errorf("format ip failed: %s", ip)
} }
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", ip, s.config.Server.Port)) listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", ip, s.config.Server.Port))