sqlite的api,便于内部使用
liuxiaolong
2021-05-24 9277f37f41d157db9e6f10b63fbe77f250980a43
voiceApi.go
@@ -25,20 +25,59 @@
}
//查找所有算法
func (api VoiceApi) FindAll()[]protomsg.Voice{
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 voiceArr
      return false, nil
   }
   var res Result
   if err = json.Unmarshal(respBody, &res); err != nil {
      logPrint(err)
      return voiceArr
      return false, nil
   }
   bytes, _ := json.Marshal(res.Data)
   err = json.Unmarshal(bytes, &voiceArr)
   return 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
}