fix(discov): move etcd hosts from URI authority to path for Go 1.26 compatibility (#5548)

This commit is contained in:
Kevin Wan
2026-04-25 10:48:28 +08:00
committed by GitHub
parent 22bdae0787
commit 4a67261b7b
6 changed files with 120 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package resolver
import (
"fmt"
"net/url"
"strings"
"github.com/zeromicro/go-zero/zrpc/resolver/internal"
@@ -14,7 +15,9 @@ func BuildDirectTarget(endpoints []string) string {
}
// BuildDiscovTarget returns a string that represents the given endpoints with discov schema.
// The format is etcd:///host1:port,host2:port?key=<etcd-key> to avoid placing comma-separated
// hosts in the URI authority, which Go 1.26+ rejects per RFC 3986.
func BuildDiscovTarget(endpoints []string, key string) string {
return fmt.Sprintf("%s://%s/%s", internal.EtcdScheme,
strings.Join(endpoints, internal.EndpointSep), key)
return fmt.Sprintf("%s:///%s?key=%s", internal.EtcdScheme,
strings.Join(endpoints, internal.EndpointSep), url.QueryEscape(key))
}