package bhomedbapi import ( "basic.com/pubsub/protomsg.git" "encoding/json" ) type ClusterApi struct { } func (api ClusterApi) FindCluster() (flag bool,info protomsg.ClusterAndNodes) { url := DATA_URL_PREFIX + "/cluster/findCluster" netNode := getNetNode(url2Topic(Topic_System_Service,url)) client := NewClient(WithNodes(netNode)) body,err := client.DoGetRequest(url, nil,nil) if err != nil { return false,info } var res Result if err = json.Unmarshal(body, &res); err != nil { return false,info } if res.Success { b, err := json.Marshal(res.Data) if err !=nil { logPrint("marshal res.Data err") return false,info } if err = json.Unmarshal(b, &info);err !=nil { return false,info } else { return true,info } } return false,info } func (api ClusterApi) Create(clusterName string, password string, virtualIp string) (bool,interface{}) { url := DATA_URL_PREFIX + "/cluster/create" netNode := getNetNode(url2Topic(Topic_System_Service,url)) client := NewClient(WithNodes(netNode)) paramBody := map[string]interface{}{ "clusterName": clusterName, "password": password, "virtualIp": virtualIp, } body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, 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 } func (api ClusterApi) Search(searchNum string, password string) (bool,interface{}) { url := DATA_URL_PREFIX + "/cluster/search" netNode := getNetNode(url2Topic(Topic_System_Service,url)) client := NewClient(WithNodes(netNode)) paramBody := map[string]interface{}{ "searchNum": searchNum, "password": password, } body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, 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 } func (api ClusterApi) GetSearchNodes() (bool,interface{}) { url := DATA_URL_PREFIX + "/cluster/getSearchNodes" netNode := getNetNode(url2Topic(Topic_System_Service,url)) client := NewClient(WithNodes(netNode)) body,err := client.DoGetRequest(url, 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 } func (api ClusterApi) StopSearching(searchNum string) (bool,interface{}) { url := DATA_URL_PREFIX + "/cluster/stopSearching" netNode := getNetNode(url2Topic(Topic_System_Service,url)) client := NewClient(WithNodes(netNode)) paramBody := map[string]interface{}{ "searchNum": searchNum, } body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, 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 } func (api ClusterApi) UpdateClusterName(clusterName string, virtualIp string) (bool,interface{}) { url := DATA_URL_PREFIX + "/cluster/updateClusterName" netNode := getNetNode(url2Topic(Topic_System_Service,url)) client := NewClient(WithNodes(netNode)) paramBody := map[string]interface{}{ "clusterName": clusterName, "virtualIp": virtualIp, } 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 } func (api ClusterApi) Leave() (bool,interface{}) { url := DATA_URL_PREFIX + "/cluster/leave" netNode := getNetNode(url2Topic(Topic_System_Service,url)) client := NewClient(WithNodes(netNode)) body,err := client.DoPostRequest(url,CONTENT_TYPE_FORM, nil,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 } func (api ClusterApi) JoinCluster(paramBody map[string]interface{}) (bool,interface{}) { url := DATA_URL_PREFIX + "/cluster/joinCluster" netNode := getNetNode(url2Topic(Topic_System_Service,url)) client := NewClient(WithNodes(netNode)) body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, 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 }