From ca7f6d5db51e18686c96fe2c2c4aaacd16625e73 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Fri, 23 Aug 2019 17:15:36 +0800 Subject: [PATCH] fix using address without http prefix Signed-off-by: Ryan Leung --- tests/pdctl/cluster/cluster_test.go | 3 +++ tools/pd-ctl/pdctl/command/global.go | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/pdctl/cluster/cluster_test.go b/tests/pdctl/cluster/cluster_test.go index 26ee802d89b..1558ea43711 100644 --- a/tests/pdctl/cluster/cluster_test.go +++ b/tests/pdctl/cluster/cluster_test.go @@ -15,6 +15,7 @@ package cluster_test import ( "encoding/json" + "strings" "testing" . "github.com/pingcap/check" @@ -45,6 +46,8 @@ func (s *clusterTestSuite) TestClusterAndPing(c *C) { c.Assert(err, IsNil) cluster.WaitLeader() pdAddr := cluster.GetConfig().GetClientURLs() + i := strings.Index(pdAddr, "//") + pdAddr = pdAddr[i+2:] cmd := pdctl.InitCommand() defer cluster.Destroy() diff --git a/tools/pd-ctl/pdctl/command/global.go b/tools/pd-ctl/pdctl/command/global.go index b098b1aebc8..6ba4c0dc555 100644 --- a/tools/pd-ctl/pdctl/command/global.go +++ b/tools/pd-ctl/pdctl/command/global.go @@ -164,7 +164,13 @@ func getEndpoints(cmd *cobra.Command) []string { cmd.Println("get pd address failed, should set flag with '-u'") os.Exit(1) } - return strings.Split(addrs, ",") + eps := strings.Split(addrs, ",") + for i, ep := range eps { + if j := strings.Index(ep, "//"); j == -1 { + eps[i] = "//" + ep + } + } + return eps } func postJSON(cmd *cobra.Command, prefix string, input map[string]interface{}) {