From cf8b732d2268727d3da6b053c8685cd626336ab3 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期四, 17 九月 2020 12:05:10 +0800
Subject: [PATCH] get tree add isPlatform arg

---
 cluster.go |   35 ++++++++++++++++++++++++++---------
 1 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/cluster.go b/cluster.go
index de4d3a8..f3992ce 100644
--- a/cluster.go
+++ b/cluster.go
@@ -1,13 +1,30 @@
 package dbapi
 
-import "encoding/json"
+import (
+	"encoding/json"
+	"strconv"
+)
 
 type ClusterApi struct {
+	Ip string
+	Port int
+}
 
+func (api ClusterApi) getBasicUrl() string {
+	if api.Ip == "" {
+		return BASIC_URL
+	}
+	if api.Ip == "" {
+		api.Ip = DEFAULT_IP
+	}
+	if api.Port == 0 {
+		api.Port = DEFAULT_PORT
+	}
+	return "http://"+api.Ip+":"+strconv.Itoa(api.Port)
 }
 
 func (api ClusterApi) FindCluster() (bool,interface{}) {
-	url := BASIC_URL + DATA_URL_PREFIX + "/cluster/findCluster"
+	url := api.getBasicUrl() + DATA_URL_PREFIX + "/cluster/findCluster"
 	client := NewClient()
 	body,err := client.DoGetRequest(url, nil,nil)
 	if err != nil {
@@ -23,7 +40,7 @@
 }
 
 func (api ClusterApi) Create(clusterName string, password string, virtualIp string) (bool,interface{}) {
-	url := BASIC_URL + DATA_URL_PREFIX + "/cluster/create"
+	url := api.getBasicUrl() + DATA_URL_PREFIX + "/cluster/create"
 	client := NewClient()
 	paramBody := map[string]interface{}{
 		"clusterName": clusterName,
@@ -44,7 +61,7 @@
 }
 
 func (api ClusterApi) Search(searchNum string, password string) (bool,interface{}) {
-	url := BASIC_URL + DATA_URL_PREFIX + "/cluster/search"
+	url := api.getBasicUrl() + DATA_URL_PREFIX + "/cluster/search"
 	client := NewClient()
 	paramBody := map[string]interface{}{
 		"searchNum": searchNum,
@@ -64,7 +81,7 @@
 }
 
 func (api ClusterApi) GetSearchNodes() (bool,interface{}) {
-	url := BASIC_URL + DATA_URL_PREFIX + "/cluster/getSearchNodes"
+	url := api.getBasicUrl() + DATA_URL_PREFIX + "/cluster/getSearchNodes"
 	client := NewClient()
 	body,err := client.DoGetRequest(url, nil,nil)
 	if err != nil {
@@ -80,7 +97,7 @@
 }
 
 func (api ClusterApi) StopSearching(searchNum string) (bool,interface{}) {
-	url := BASIC_URL + DATA_URL_PREFIX + "/cluster/stopSearching"
+	url := api.getBasicUrl() + DATA_URL_PREFIX + "/cluster/stopSearching"
 	client := NewClient()
 	paramBody := map[string]interface{}{
 		"searchNum": searchNum,
@@ -99,7 +116,7 @@
 }
 
 func (api ClusterApi) UpdateClusterName(clusterName string, virtualIp string) (bool,interface{}) {
-	url := BASIC_URL + DATA_URL_PREFIX + "/cluster/updateClusterName"
+	url := api.getBasicUrl() + DATA_URL_PREFIX + "/cluster/updateClusterName"
 	client := NewClient()
 	paramBody := map[string]interface{}{
 		"clusterName": clusterName,
@@ -119,7 +136,7 @@
 }
 
 func (api ClusterApi) Leave() (bool,interface{}) {
-	url := BASIC_URL + DATA_URL_PREFIX + "/cluster/leave"
+	url := api.getBasicUrl() + DATA_URL_PREFIX + "/cluster/leave"
 	client := NewClient()
 	body,err := client.DoPostRequest(url,CONTENT_TYPE_FORM, nil,nil,nil)
 	if err != nil {
@@ -136,7 +153,7 @@
 
 
 func (api ClusterApi) JoinCluster(paramBody map[string]interface{}) (bool,interface{}) {
-	url := BASIC_URL + DATA_URL_PREFIX + "/cluster/joinCluster"
+	url := api.getBasicUrl() + DATA_URL_PREFIX + "/cluster/joinCluster"
 	client := NewClient()
 	body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, paramBody,nil,nil)
 	if err != nil {

--
Gitblit v1.8.0