MCPcopy
hub / github.com/gofiber/fiber / BalancerForward

Function BalancerForward

middleware/proxy/proxy.go:276–292  ·  view source on GitHub ↗

BalancerForward Forward performs the given http request with round robin algorithm to server and fills the given http response. This method will return a fiber.Handler

(servers []string, clients ...*fasthttp.Client)

Source from the content-addressed store, hash-verified

274// BalancerForward Forward performs the given http request with round robin algorithm to server and fills the given http response.
275// This method will return a fiber.Handler
276func BalancerForward(servers []string, clients ...*fasthttp.Client) fiber.Handler {
277 if len(servers) == 0 {
278 panic("Servers cannot be empty")
279 }
280 r := &roundrobin{
281 current: 0,
282 pool: servers,
283 }
284 return func(c fiber.Ctx) error {
285 server := r.get()
286 if !strings.HasPrefix(server, "http") {
287 server = "http://" + server
288 }
289 c.Request().Header.Set("X-Real-IP", c.IP())
290 return Do(c, server+c.OriginalURL(), clients...)
291 }
292}

Calls 6

getMethod · 0.95
DoFunction · 0.85
SetMethod · 0.65
RequestMethod · 0.65
IPMethod · 0.65
OriginalURLMethod · 0.65