MCPcopy Create free account
hub / github.com/appleboy/loadbalancer-algorithms / ExampleRoundRobin

Function ExampleRoundRobin

roundrobin/roundrobin_test.go:211–252  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

209}
210
211func ExampleRoundRobin() {
212 servers := []*proxy.Proxy{
213 proxy.NewProxy("s1", &url.URL{Host: "192.168.1.10"}),
214 proxy.NewProxy("s2", &url.URL{Host: "192.168.1.11"}),
215 proxy.NewProxy("s3", &url.URL{Host: "192.168.1.12"}),
216 }
217 r, _ := New(servers...)
218
219 fmt.Println(r.NextServer().GetName())
220 fmt.Println(r.NextServer().GetName())
221 fmt.Println(r.NextServer().GetName())
222 fmt.Println(r.NextServer().GetName())
223 fmt.Println()
224
225 addServers := []*proxy.Proxy{
226 proxy.NewProxy("d1", &url.URL{Host: "192.168.2.10"}),
227 proxy.NewProxy("d2", &url.URL{Host: "192.168.2.11"}),
228 proxy.NewProxy("d3", &url.URL{Host: "192.168.2.12"}),
229 }
230
231 _ = r.AddServers(addServers...)
232
233 fmt.Println(r.NextServer().GetName())
234 fmt.Println(r.NextServer().GetName())
235 fmt.Println(r.NextServer().GetName())
236 fmt.Println(r.NextServer().GetName())
237 fmt.Println(r.NextServer().GetName())
238 fmt.Println(r.NextServer().GetName())
239
240 // Output:
241 // s1
242 // s2
243 // s3
244 // s1
245 //
246 // d2
247 // d3
248 // s1
249 // s2
250 // s3
251 // d1
252}

Callers

nothing calls this directly

Calls 5

NewProxyFunction · 0.92
GetNameMethod · 0.80
NewFunction · 0.70
NextServerMethod · 0.65
AddServersMethod · 0.65

Tested by

no test coverage detected