diff --git a/api/gateway/tron/internal/service/gateway/tronclient/client.go b/api/gateway/tron/internal/service/gateway/tronclient/client.go index cb9504ea..617c4b04 100644 --- a/api/gateway/tron/internal/service/gateway/tronclient/client.go +++ b/api/gateway/tron/internal/service/gateway/tronclient/client.go @@ -107,28 +107,30 @@ func newForceIPv4Dialer(host, port string) func(context.Context, string) (net.Co func normalizeGRPCAddress(grpcURL string) (string, bool, error) { target := strings.TrimSpace(grpcURL) - useTLS := false if target == "" { return "", false, merrors.InvalidArgument("tronclient: grpc url is required") } - if strings.Contains(target, "://") { - u, err := url.Parse(target) - if err != nil { - return "", false, merrors.InvalidArgument("tronclient: invalid grpc url") - } - if u.Scheme == "https" || u.Scheme == "grpcs" { - useTLS = true - } - host := strings.TrimSpace(u.Host) - if host == "" { - return "", false, merrors.InvalidArgument("tronclient: grpc url missing host") - } - if useTLS && u.Port() == "" { - host = host + ":443" - } - return host, useTLS, nil + + // Default to secure gRPC when no scheme is provided. + if !strings.Contains(target, "://") { + target = "grpcs://" + target } - return target, useTLS, nil + + u, err := url.Parse(target) + if err != nil { + return "", false, merrors.InvalidArgument("tronclient: invalid grpc url") + } + + useTLS := u.Scheme == "https" || u.Scheme == "grpcs" + host := strings.TrimSpace(u.Host) + if host == "" { + return "", false, merrors.InvalidArgument("tronclient: grpc url missing host") + } + if useTLS && u.Port() == "" { + host = host + ":443" + } + + return host, useTLS, nil } func grpcTokenUnaryInterceptor(token string) grpc.UnaryClientInterceptor {