消除错误处理
This commit is contained in:
17
bin/main.go
17
bin/main.go
@@ -301,22 +301,9 @@ func main() {
|
||||
}
|
||||
var conditions strings.Builder
|
||||
// 如果是查询 text, 直接从 Elasticsearch 返回结果
|
||||
var text_ids []int
|
||||
var text_ids []string
|
||||
if text := QueryConditions("text"); len(text) > 0 {
|
||||
rest := models.ElasticsearchSearch(strings.Join(text, " "))
|
||||
if rest == nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
for _, hit := range rest["hits"].(map[string]interface{})["hits"].([]interface{}) {
|
||||
id, err := strconv.Atoi(hit.(map[string]interface{})["_id"].(string))
|
||||
if err != nil {
|
||||
log.Println("strconv.Atoi failed:", err)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
text_ids = append(text_ids, id)
|
||||
}
|
||||
text_ids := models.ElasticsearchSearch(strings.Join(text, " ")).GetIDList()
|
||||
if len(text_ids) > 0 {
|
||||
conditions.WriteString(fmt.Sprintf(" WHERE id IN (%s)", strings.Trim(strings.Replace(fmt.Sprint(text_ids), " ", ",", -1), "[]")))
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user