config upgrale & cleanup

This commit is contained in:
ycc
2024-09-27 09:31:45 +02:00
parent 87a1759ac4
commit 3a4e950200
6 changed files with 174 additions and 99 deletions

View File

@@ -1,13 +1,6 @@
package models
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"strings"
"github.com/google/uuid"
"github.com/tidwall/gjson"
)
@@ -90,30 +83,30 @@ func doSinglePeerSearch(peerId SearchTarget, query string, searchId string) erro
// update percent in Redis
// feed results to Zinc
bulk := map[string]interface{}{"index": "search_" + searchId, "records": indexedPeers}
raw, err := json.Marshal(bulk)
if err != nil {
return err
}
req, err := http.NewRequest("POST", GetConfig().ZincUrl+"/api/_bulkv2", strings.NewReader(string(raw)))
if err != nil {
return err
}
req.SetBasicAuth(GetConfig().ZincLogin, GetConfig().ZincPassword)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36")
// bulk := map[string]interface{}{"index": "search_" + searchId, "records": indexedPeers}
// raw, err := json.Marshal(bulk)
// if err != nil {
// return err
// }
// req, err := http.NewRequest("POST", GetConfig().ZincUrl+"/api/_bulkv2", strings.NewReader(string(raw)))
// if err != nil {
// return err
// }
// req.SetBasicAuth(GetConfig().ZincLogin, GetConfig().ZincPassword)
// req.Header.Set("Content-Type", "application/json")
// req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
log.Println(resp.StatusCode)
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
fmt.Println(string(body))
// resp, err := http.DefaultClient.Do(req)
// if err != nil {
// return err
// }
// defer resp.Body.Close()
// log.Println(resp.StatusCode)
// body, err = io.ReadAll(resp.Body)
// if err != nil {
// return err
// }
// fmt.Println(string(body))
// query Zinc
// remerge results in types