fix: resolve gRPC Gateway connection issue when server address is empty

When Profile.Addr is empty (default configuration), gRPC Gateway
attempts to connect to ":port" which fails on macOS with transport
errors. This fix defaults to "localhost" when no address is specified,
ensuring cross-platform compatibility.

- Fix gRPC connection format from ":port" to "localhost:port"
- Resolves API endpoint failures in development environment
- Maintains compatibility with explicit address configurations

Fixes connection error: "transport: Error while dialing: reading
server HTTP response: unexpected EOF"

Signed-off-by: ChaoLiu <chaoliu719@gmail.com>
This commit is contained in:
ChaoLiu 2025-08-05 13:34:29 +08:00
parent aae7ec8d1f
commit 7db3e02fe7
1 changed files with 5 additions and 1 deletions

View File

@ -67,7 +67,11 @@ func NewAPIV1Service(secret string, profile *profile.Profile, store *store.Store
func (s *APIV1Service) RegisterGateway(ctx context.Context, echoServer *echo.Echo) error {
var target string
if len(s.Profile.UNIXSock) == 0 {
target = fmt.Sprintf("%s:%d", s.Profile.Addr, s.Profile.Port)
addr := s.Profile.Addr
if addr == "" {
addr = "localhost"
}
target = fmt.Sprintf("%s:%d", addr, s.Profile.Port)
} else {
target = fmt.Sprintf("unix:%s", s.Profile.UNIXSock)
}