package backtrace import ( "fmt" "io" "strings" "time" "github.com/imroc/req/v3" "github.com/oneclickvirt/backtrace/model" . "github.com/oneclickvirt/defaultset" ) type Result struct { i int s string } func removeDuplicates(elements []string) []string { encountered := map[string]bool{} // 用于存储已经遇到的元素 result := []string{} // 存储去重后的结果 for v := range elements { // 遍历切片中的元素 if encountered[elements[v]] == true { // 如果该元素已经遇到过 // 存在过就不加入了 } else { encountered[elements[v]] = true // 将该元素标记为已经遇到 result = append(result, elements[v]) // 将该元素加入到结果切片中 } } return result // 返回去重后的结果切片 } func getData(endpoint string) string { client := req.C() client.SetTimeout(10 * time.Second) client.R(). SetRetryCount(2). SetRetryBackoffInterval(1*time.Second, 5*time.Second). SetRetryFixedInterval(2 * time.Second) if model.EnableLoger { InitLogger() defer Logger.Sync() } for _, baseUrl := range model.CdnList { url := baseUrl + endpoint resp, err := client.R().Get(url) if err == nil { defer resp.Body.Close() b, err := io.ReadAll(resp.Body) if strings.Contains(string(b), "error") { continue } if err == nil { if model.EnableLoger { Logger.Info(fmt.Sprintf("Received data length: %d", len(b))) } return string(b) } } if model.EnableLoger { Logger.Info(fmt.Sprintf("HTTP request failed: %v", err)) } } return "" }