()
| 8 | ) |
| 9 | |
| 10 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…