sqlite的api,便于内部使用
liuxiaolong
2021-05-24 aeeadc95e1b1218a85f3b48da8dc5b4b57aeb219
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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() (bool, []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 false, nil
    }
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        logPrint(err)
        return false, nil
    }
    bytes, _ := json.Marshal(res.Data)
    err = json.Unmarshal(bytes, &voiceArr)
    return res.Success, voiceArr
}
 
func (api VoiceApi) Add(id,name,mp3File,g711aFile string) (bool, interface{}) {
    url := api.getBasicUrl() + DATA_URL_PREFIX + "/voice/add"
    client := NewClient()
    paramBody := map[string]interface{}{
        "id": id,
        "name": name,
        "mp3File": mp3File,
        "g711aFile": g711aFile,
    }
    respBody, err := client.DoPostRequest(url,CONTENT_TYPE_FORM, paramBody, nil, nil)
    if err !=nil {
        return false, nil
    }
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        logPrint(err)
        return false, nil
    }
    return res.Success, res.Data 
}
 
func (api VoiceApi) Del(id string) (bool, interface{}) {
    url := api.getBasicUrl() + DATA_URL_PREFIX + "/voice/del"
    client := NewClient()
    paramQuery := map[string]string {
        "id": id,
    }
    respBody, err := client.DoDeleteRequest(url,CONTENT_TYPE_FORM, nil, paramQuery, nil)
    if err !=nil {
        return false, nil
    }
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        logPrint(err)
        return false, nil
    }
    return res.Success, res.Data
}