use predefined endpoint separator

master v1.0.6
kevin 4 years ago
parent f3c367a323
commit 456b395860

@ -12,7 +12,7 @@ func (d *directBuilder) Build(target resolver.Target, cc resolver.ClientConn, op
resolver.Resolver, error) {
var addrs []resolver.Address
endpoints := strings.FieldsFunc(target.Endpoint, func(r rune) bool {
return r == EndpointSep
return r == EndpointSepChar
})
for _, val := range subset(endpoints, subsetSize) {

@ -12,7 +12,7 @@ type discovBuilder struct{}
func (d *discovBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (
resolver.Resolver, error) {
hosts := strings.FieldsFunc(target.Authority, func(r rune) bool {
return r == EndpointSep
return r == EndpointSepChar
})
sub, err := discov.NewSubscriber(hosts, target.Endpoint)
if err != nil {

@ -1,15 +1,20 @@
package resolver
import "google.golang.org/grpc/resolver"
import (
"fmt"
"google.golang.org/grpc/resolver"
)
const (
DirectScheme = "direct"
DiscovScheme = "discov"
EndpointSep = ','
EndpointSepChar = ','
subsetSize = 32
)
var (
EndpointSep = fmt.Sprintf("%c", EndpointSepChar)
dirBuilder directBuilder
disBuilder discovBuilder
)

@ -8,11 +8,11 @@ import (
)
func BuildDirectTarget(endpoints []string) string {
return fmt.Sprintf("%s:///%s", resolver.DirectScheme, strings.Join(
endpoints, fmt.Sprintf("%c", resolver.EndpointSep)))
return fmt.Sprintf("%s:///%s", resolver.DirectScheme,
strings.Join(endpoints, resolver.EndpointSep))
}
func BuildDiscovTarget(endpoints []string, key string) string {
return fmt.Sprintf("%s://%s/%s", resolver.DiscovScheme, strings.Join(
endpoints, fmt.Sprintf("%c", resolver.EndpointSep)), key)
return fmt.Sprintf("%s://%s/%s", resolver.DiscovScheme,
strings.Join(endpoints, resolver.EndpointSep), key)
}

Loading…
Cancel
Save