From 5a9b7c4a4f926aaf79fbcc6356fe9e2a77cd248d Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期一, 02 十一月 2020 16:28:43 +0800
Subject: [PATCH] 添加算法的delete
---
cluster.go | 67 ++++++++++++++++++++++++++-------
1 files changed, 52 insertions(+), 15 deletions(-)
diff --git a/cluster.go b/cluster.go
index de4d3a8..b25d360 100644
--- a/cluster.go
+++ b/cluster.go
@@ -1,29 +1,48 @@
package dbapi
-import "encoding/json"
+import (
+ "basic.com/pubsub/protomsg.git"
+ "encoding/json"
+ "strconv"
+)
type ClusterApi struct {
-
+ Ip string
+ Port int
}
-func (api ClusterApi) FindCluster() (bool,interface{}) {
- url := BASIC_URL + DATA_URL_PREFIX + "/cluster/findCluster"
+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() (b bool,c protomsg.ClusterAndNodes) {
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/cluster/findCluster"
client := NewClient()
body,err := client.DoGetRequest(url, nil,nil)
if err != nil {
- return false,nil
+ return false,c
}
var res Result
if err = json.Unmarshal(body, &res); err != nil {
- return false,nil
+ return false,c
}
-
- return res.Success,res.Data
+ bytes, _ := json.Marshal(res.Data)
+ err = json.Unmarshal(bytes, &c)
+ return res.Success,c
}
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 +63,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 +83,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 +99,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 +118,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 +138,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 +155,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 {
@@ -152,4 +171,22 @@
}
+func (api ClusterApi) UpdateDriftState(driftState string, nodeId string) (bool,interface{}) {
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/cluster/updateDriftState"
+ client := NewClient()
+ paramBody := map[string]interface{}{
+ "driftState": driftState,
+ "nodeId": nodeId,
+ }
+ body,err := client.DoPostRequest(url,CONTENT_TYPE_FORM, paramBody,nil,nil)
+ if err != nil {
+ return false,nil
+ }
+ var res Result
+ if err = json.Unmarshal(body, &res); err != nil {
+ return false,nil
+ }
+
+ return res.Success,res.Data
+}
--
Gitblit v1.8.0