2021-12-01 20:22:15 +08:00
|
|
|
package resolver
|
2020-08-18 18:36:44 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2026-04-25 10:48:28 +08:00
|
|
|
"net/url"
|
2020-08-18 18:36:44 +08:00
|
|
|
"strings"
|
|
|
|
|
|
2022-01-04 15:51:32 +08:00
|
|
|
"github.com/zeromicro/go-zero/zrpc/resolver/internal"
|
2020-08-18 18:36:44 +08:00
|
|
|
)
|
|
|
|
|
|
2021-03-01 23:52:44 +08:00
|
|
|
// BuildDirectTarget returns a string that represents the given endpoints with direct schema.
|
2020-08-18 18:36:44 +08:00
|
|
|
func BuildDirectTarget(endpoints []string) string {
|
2021-12-01 20:22:15 +08:00
|
|
|
return fmt.Sprintf("%s:///%s", internal.DirectScheme,
|
|
|
|
|
strings.Join(endpoints, internal.EndpointSep))
|
2020-08-18 18:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
2021-03-01 23:52:44 +08:00
|
|
|
// BuildDiscovTarget returns a string that represents the given endpoints with discov schema.
|
2026-04-25 10:48:28 +08:00
|
|
|
// 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.
|
2020-08-18 18:36:44 +08:00
|
|
|
func BuildDiscovTarget(endpoints []string, key string) string {
|
2026-04-25 10:48:28 +08:00
|
|
|
return fmt.Sprintf("%s:///%s?key=%s", internal.EtcdScheme,
|
|
|
|
|
strings.Join(endpoints, internal.EndpointSep), url.QueryEscape(key))
|
2020-08-18 18:36:44 +08:00
|
|
|
}
|