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 }