mirror of
https://github.com/labstack/echo.git
synced 2024-11-24 08:22:21 +02:00
Updated godco for middleware/proxy
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
0898d9e68b
commit
68b89eca6c
8
Gopkg.lock
generated
8
Gopkg.lock
generated
@ -61,12 +61,6 @@
|
||||
packages = ["acme","acme/autocert"]
|
||||
revision = "e1a4589e7d3ea14a3352255d04b6f1a418845e5e"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/net"
|
||||
packages = ["websocket"]
|
||||
revision = "e4fa1c5465ad6111f206fc92186b8c83d64adbe1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/sys"
|
||||
@ -76,6 +70,6 @@
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "e6ecdde9a4df2afdf849e47fd5a0680122ec991fbadea0a59e54d36b52e8f681"
|
||||
inputs-digest = "5f74a2a2ba5b07475ad0faa1b4c021b973ad40b2ae749e3d94e15fe839bb440e"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
@ -21,11 +21,11 @@ type (
|
||||
// Skipper defines a function to skip middleware.
|
||||
Skipper Skipper
|
||||
|
||||
// Balance defines a load balancing technique.
|
||||
// Balancer defines a load balancing technique.
|
||||
// Required.
|
||||
// Possible values:
|
||||
// - ProxyRandom
|
||||
// - ProxyRoundRobin
|
||||
// - RandomBalancer
|
||||
// - RoundRobinBalancer
|
||||
Balancer ProxyBalancer
|
||||
}
|
||||
|
||||
@ -34,16 +34,19 @@ type (
|
||||
URL *url.URL
|
||||
}
|
||||
|
||||
// RandomBalancer implements a random load balancing technique.
|
||||
RandomBalancer struct {
|
||||
Targets []*ProxyTarget
|
||||
random *rand.Rand
|
||||
}
|
||||
|
||||
// RoundRobinBalancer implements a round-robin load balancing technique.
|
||||
RoundRobinBalancer struct {
|
||||
Targets []*ProxyTarget
|
||||
i uint32
|
||||
}
|
||||
|
||||
// ProxyBalancer defines an interface to implement a load balancing technique.
|
||||
ProxyBalancer interface {
|
||||
Next() *ProxyTarget
|
||||
}
|
||||
@ -98,6 +101,7 @@ func proxyRaw(t *ProxyTarget, c echo.Context) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
// Next randomly returns an upstream target.
|
||||
func (r *RandomBalancer) Next() *ProxyTarget {
|
||||
if r.random == nil {
|
||||
r.random = rand.New(rand.NewSource(int64(time.Now().Nanosecond())))
|
||||
@ -105,6 +109,7 @@ func (r *RandomBalancer) Next() *ProxyTarget {
|
||||
return r.Targets[r.random.Intn(len(r.Targets))]
|
||||
}
|
||||
|
||||
// Next returns an upstream target using round-robin technique.
|
||||
func (r *RoundRobinBalancer) Next() *ProxyTarget {
|
||||
r.i = r.i % uint32(len(r.Targets))
|
||||
t := r.Targets[r.i]
|
||||
|
Loading…
Reference in New Issue
Block a user