From 9310ffbc345378d4a2b21883f341fc909a011f93 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期一, 13 七月 2020 15:18:36 +0800
Subject: [PATCH] add voiceApi
---
soApi.go | 28 ++++++++++++++++++++++------
1 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/soApi.go b/soApi.go
index ec35758..02caeee 100644
--- a/soApi.go
+++ b/soApi.go
@@ -3,14 +3,30 @@
import (
"basic.com/pubsub/protomsg.git"
"encoding/json"
- "fmt"
+ "strconv"
)
-type SoApi struct {}
+type SoApi struct {
+ Ip string
+ Port int
+}
+
+func (api SoApi) 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)
+}
//鑾峰彇鎵�鏈塻dkId涓巗oName鏄犲皠淇℃伅
func (api SoApi) FindAll() (soInfos []protomsg.SoInfo) {
- url := BASIC_URL + DATA_URL_PREFIX + "/so/findAll"
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/so/findAll"
client := NewClient()
respBody, err := client.DoGetRequest(url, nil, nil)
@@ -19,7 +35,7 @@
}
var res Result
if err = json.Unmarshal(respBody, &res); err != nil {
- fmt.Println(err)
+ logPrint(err)
return soInfos
}
bytes, _ := json.Marshal(res.Data)
@@ -28,7 +44,7 @@
}
func (api SoApi) Add(paramBody map[string]interface{}) (bool,interface{}) {
- url := BASIC_URL + DATA_URL_PREFIX + "/so/addSo"
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/so/addSo"
client := NewClient()
respBody, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody, nil, nil)
if err != nil {
@@ -36,7 +52,7 @@
}
var res Result
if err = json.Unmarshal(respBody, &res); err != nil {
- fmt.Println(err)
+ logPrint(err)
return false,nil
}
return res.Success,res.Data
--
Gitblit v1.8.0