mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 11:47:36 +08:00
fix endpoint value check failure bug
This commit is contained in:
parent
43c3decd58
commit
52cc824882
@ -136,16 +136,24 @@ func (e *etcdClusterClient) GetEndpoints(key string) (result []string) {
|
||||
}
|
||||
//Return data check
|
||||
for _, v := range res {
|
||||
endpointURL, err := url.Parse(v)
|
||||
if err != nil || endpointURL.Host == "" || endpointURL.Path != "" {
|
||||
continue
|
||||
if checkURL(v) {
|
||||
result = append(result, v)
|
||||
}
|
||||
result = append(result, v)
|
||||
}
|
||||
}
|
||||
logrus.Infof("Get endpoints %s => %v", key, result)
|
||||
return
|
||||
}
|
||||
func checkURL(source string) bool {
|
||||
endpointURL, err := url.Parse(source)
|
||||
if err != nil && strings.Contains(err.Error(), "first path segment in URL cannot contain colon") {
|
||||
endpointURL, err = url.Parse(fmt.Sprintf("tcp://%s", source))
|
||||
}
|
||||
if err != nil || endpointURL.Host == "" || endpointURL.Path != "" {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
//SetEndpoints service name and hostip must set
|
||||
func (e *etcdClusterClient) SetEndpoints(serviceName, hostIP string, value []string) {
|
||||
@ -156,8 +164,7 @@ func (e *etcdClusterClient) SetEndpoints(serviceName, hostIP string, value []str
|
||||
return
|
||||
}
|
||||
for _, v := range value {
|
||||
endpointURL, err := url.Parse(v)
|
||||
if err != nil || endpointURL.Host == "" || endpointURL.Path != "" {
|
||||
if !checkURL(v) {
|
||||
logrus.Warningf("%s service host %s endpoint value %s invalid", serviceName, hostIP, v)
|
||||
continue
|
||||
}
|
||||
|
@ -119,6 +119,8 @@ func TestSetEndpoints(t *testing.T) {
|
||||
c.SetEndpoints("etcd", "DSASD", []string{"http://:8080"})
|
||||
c.SetEndpoints("etcd", "192.168.1.1", []string{"http://:8080"})
|
||||
c.SetEndpoints("etcd", "192.168.1.1", []string{"http://192.168.1.1:8080"})
|
||||
c.SetEndpoints("node", "192.168.2.137", []string{"192.168.2.137:10252"})
|
||||
t.Logf("check: %v", checkURL("192.168.2.137:10252"))
|
||||
}
|
||||
|
||||
func TestGetEndpoints(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user