Ukukhetha i-proxy ye-round-robin ku-Colly nge-SetProxyFunc
Sebenzisa i-SetProxyFunc ukukhetha nge-round-robin, ubheka imiphumela ye-keep-alive, ukushintshwa kwe-transport kanye ne-backend ekhoshiwe.
collector := colly.NewCollector()
switcher, err := proxy.RoundRobinProxySwitcher(
"http://proxy-a.example:8080",
"http://proxy-b.example:8080",
)
if err != nil {
return err
}
collector.SetProxyFunc(switcher)
err = collector.Visit("https://www.example.com/")Sebenzisa github.com/gocolly/colly/v2 kanye nephakethe lalo proxy emsebenzini wohlelo lokusebenza, ugcina ukusingathwa kwamaphutha okuvamile. Lungiselela isikhethi ngaphambi kokuba izicelo noma ukuvakasha okungahambisani kuqale. Uhlu lwama-proxy e-HTTP lunikeza abantu abazongenela ukhetho lwe-endpoint yesishintshi.
SetProxy ikhetha i-endpoint eqinile; SetProxyFunc ivumela i-transport ye-HTTP ukuthi ikhethe isicelo ngasinye. Lokhu kugwema ukushintsha ukucushwa okwabiwe ngaphakathi kwe-callback ngayinye ye-OnRequest.
Kulokhu kusetshenziswa, i-SetProxyFunc ibuye isethe i-DisableKeepAlives ibe true. Ibuyekeza i-*http.Transport ekhona, kodwa ishintsha olunye uhlobo lwe-transport nge-transport entsha ye-HTTP. Gcina ngamabomu noma yikuphi ukuziphatha kwe-RoundTripper yangokwezifiso esikhundleni sokucabanga ukuthi kuzophila.
I-Collector.Clone ihlanganyela i-backend ye-HTTP, ngakho ukushintsha i-proxy yekhophi kungashintsha leyondlela i-backend eyabiwe. Thatha isinqumo sobunikazi ngaphambi komsebenzi wesikhathi esisodwa. Ukukhetha kwe-round-robin kujikeleza ama-endpoint anikeziwe, hhayi ubunikazi bokuphuma obusesidlangalaleni obuqinisekisiwe noma ukutholakala okuhlolwe ngokuzimela.