You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/06/20 00:32:42 UTC

[GitHub] [pulsar-client-go] cugxuan commented on a change in pull request #291: [Issue 177] feature: support multi host

cugxuan commented on a change in pull request #291:
URL: https://github.com/apache/pulsar-client-go/pull/291#discussion_r443084654



##########
File path: pulsar/internal/host_resolve.go
##########
@@ -0,0 +1,107 @@
+package internal
+
+import (
+	"errors"
+	"math/rand"
+	"net/url"
+	"strings"
+	"sync"
+	"time"
+
+	log "github.com/sirupsen/logrus"
+)
+
+// HostResolve is used to implement multihost
+type HostResolve interface {
+	GetServiceURL() string
+	GetHost() (*url.URL, error)
+	GetHostURL() (string, error)
+	ResolveHost() (*url.URL, error)
+}
+
+type hostResolve struct {
+	serviceURL   string
+	Host         []*url.URL
+	CurrentIndex int
+}
+
+func NewHostResolve(serviceURL string) (HostResolve, error) {
+	h := &hostResolve{
+		serviceURL: serviceURL,
+	}
+
+	// resolve host
+	hosts := strings.Split(h.serviceURL, ",")
+	if len(hosts) == 0 || !checkPrefix(hosts[0]) {
+		return nil, errors.New("invalid service URL")
+	}
+
+	for k := range hosts {
+		if !checkPrefix(hosts[k]) {

Review comment:
       Oh, This is something I didn’t think about!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org