From f529b0fe67d68a4be6e9690043ee5d6837be72df Mon Sep 17 00:00:00 2001
From: 554325746@qq.com <554325746@qq.com>
Date: 星期二, 12 一月 2021 11:05:50 +0800
Subject: [PATCH] getAppInfo and voice add
---
eventPush.go | 66 +++++++++++++++++++++++++-------
1 files changed, 51 insertions(+), 15 deletions(-)
diff --git a/eventPush.go b/eventPush.go
index 9dbd7a8..c32c6c6 100644
--- a/eventPush.go
+++ b/eventPush.go
@@ -1,16 +1,31 @@
package dbapi
import (
+ "basic.com/pubsub/protomsg.git"
"encoding/json"
- "fmt"
+ "strconv"
)
type EventPushApi struct {
+ Ip string
+ Port int
+}
+func (api EventPushApi) 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 EventPushApi) Save(paramBody map[string]interface{}) (bool,interface{}){
- url := BASIC_URL + DATA_URL_PREFIX + "/eventPush/save"
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/eventPush/save"
client := NewClient()
body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, paramBody,nil,nil)
if err != nil {
@@ -19,7 +34,7 @@
var res Result
if err = json.Unmarshal(body, &res); err != nil {
- fmt.Println(err)
+ logPrint(err)
return false,nil
}
@@ -27,7 +42,7 @@
}
func (api EventPushApi) FindByEventTopic(topic string,childType string) (bool,interface{}){
- url := BASIC_URL + DATA_URL_PREFIX + "/eventPush/findByEventTopic"
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/eventPush/findByEventTopic"
client := NewClient()
paramQuery :=make(map[string]string,0)
paramQuery["topic"] = topic
@@ -45,7 +60,7 @@
}
func (api EventPushApi) FindAll(name string) (bool,interface{}){
- url := BASIC_URL + DATA_URL_PREFIX + "/eventPush/findAll"
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/eventPush/findAll"
client := NewClient()
paramQuery :=make(map[string]string,0)
paramQuery["name"] = name
@@ -61,8 +76,29 @@
return true,res.Data
}
+func (api EventPushApi) FindAllDetails() (b bool,allRules []protomsg.EventPush){
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/eventPush/findAllDetails"
+ client := NewClient()
+ 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
+ }
+ bytes, _ := json.Marshal(res.Data)
+ err = json.Unmarshal(bytes, &allRules)
+ if err !=nil{
+ logPrint("all eventPushRules unmarshal err:",err)
+ return false,nil
+ }
+ return true,allRules
+}
+
func (api EventPushApi) GetById(id string) (bool,interface{}){
- url := BASIC_URL + DATA_URL_PREFIX + "/eventPush/getById"
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/eventPush/getById"
client := NewClient()
paramQuery :=make(map[string]string,0)
paramQuery["id"] = id
@@ -78,13 +114,13 @@
return true,res.Data
}
-func (api EventPushApi) ChangeStatus(id string,enable string) (bool,interface{}){
- url := BASIC_URL + DATA_URL_PREFIX + "/eventPush/changeStatus"
+func (api EventPushApi) ChangeStatus(id string,enable bool) (bool,interface{}){
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/eventPush/changeStatus"
client := NewClient()
- paramForm :=make(map[string]string,0)
- paramForm["id"] = id
- paramForm["enable"] = enable
- body, err := client.DoPostRequest(url, CONTENT_TYPE_FORM,nil, paramForm, nil)
+ paramBody :=make(map[string]interface{},0)
+ paramBody["id"] = id
+ paramBody["enable"] = enable
+ body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON,paramBody, nil, nil)
if err != nil {
return false,nil
}
@@ -97,11 +133,11 @@
}
func (api EventPushApi) Delete(id string) (bool,interface{}){
- url := BASIC_URL + DATA_URL_PREFIX + "/eventPush/delete"
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/eventPush/delete"
client := NewClient()
- paramForm :=make(map[string]string,0)
+ paramForm :=make(map[string]interface{},0)
paramForm["id"] = id
- body, err := client.DoPostRequest(url, CONTENT_TYPE_FORM,nil, paramForm, nil)
+ body, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramForm, nil, nil)
if err != nil {
return false,nil
}
--
Gitblit v1.8.0