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
---
voiceApi.go | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/voiceApi.go b/voiceApi.go
new file mode 100644
index 0000000..57c2b9c
--- /dev/null
+++ b/voiceApi.go
@@ -0,0 +1,44 @@
+package dbapi
+
+import (
+ "basic.com/pubsub/protomsg.git"
+ "encoding/json"
+ "strconv"
+)
+
+type VoiceApi struct{
+ Ip string
+ Port int
+}
+
+func (api VoiceApi) 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 VoiceApi) FindAll()[]protomsg.Voice{
+ var voiceArr []protomsg.Voice
+ url := api.getBasicUrl() + DATA_URL_PREFIX + "/voice/findAll"
+ client := NewClient()
+ respBody, err := client.DoGetRequest(url, nil, nil)
+ if err !=nil {
+ return voiceArr
+ }
+ var res Result
+ if err = json.Unmarshal(respBody, &res); err != nil {
+ logPrint(err)
+ return voiceArr
+ }
+ bytes, _ := json.Marshal(res.Data)
+ err = json.Unmarshal(bytes, &voiceArr)
+ return voiceArr
+}
\ No newline at end of file
--
Gitblit v1.8.0