MCPcopy
hub / github.com/valyala/fasthttp / ExampleLBClient

Function ExampleLBClient

lbclient_example_test.go:10–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8)
9
10func ExampleLBClient() {
11 // Requests will be spread among these servers.
12 servers := []string{
13 "google.com:80",
14 "foobar.com:8080",
15 "127.0.0.1:123",
16 }
17
18 // Prepare clients for each server
19 var lbc fasthttp.LBClient
20 for _, addr := range servers {
21 c := &fasthttp.HostClient{
22 Addr: addr,
23 }
24 lbc.Clients = append(lbc.Clients, c)
25 }
26
27 // Send requests to load-balanced servers
28 var req fasthttp.Request
29 var resp fasthttp.Response
30 for i := range 10 {
31 url := fmt.Sprintf("http://abcedfg/foo/bar/%d", i)
32 req.SetRequestURI(url)
33 if err := lbc.Do(&req, &resp); err != nil {
34 log.Fatalf("Error when sending request: %v", err)
35 }
36 if resp.StatusCode() != fasthttp.StatusOK {
37 log.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode(), fasthttp.StatusOK)
38 }
39
40 useResponseBody(resp.Body())
41 }
42}

Callers

nothing calls this directly

Calls 5

SetRequestURIMethod · 0.95
DoMethod · 0.95
StatusCodeMethod · 0.95
BodyMethod · 0.95
useResponseBodyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…