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:
parent
986fcedb4d
commit
18fb640417
|
|
@ -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))
|
||||||
|
|
|
||||||
|
|
@ -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))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue