summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-05-16 16:05:38 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-05-16 16:05:38 -0600
commit1f0c061ce30f218e63fcc17e0fdfc8b90d754ba5 (patch)
treeef148ac39ec520d14342ce48cec07f5efe0379f3 /modules/caddyhttp/reverseproxy
parentff5b4639d597203f8aec43e5eae8fe3774976d32 (diff)
Architectural shift to using context for config and module state
Diffstat (limited to 'modules/caddyhttp/reverseproxy')
-rwxr-xr-xmodules/caddyhttp/reverseproxy/module.go33
-rwxr-xr-xmodules/caddyhttp/reverseproxy/upstream.go4
2 files changed, 2 insertions, 35 deletions
diff --git a/modules/caddyhttp/reverseproxy/module.go b/modules/caddyhttp/reverseproxy/module.go
index cc53bf5..1bfc9ad 100755
--- a/modules/caddyhttp/reverseproxy/module.go
+++ b/modules/caddyhttp/reverseproxy/module.go
@@ -1,8 +1,6 @@
package reverseproxy
import (
- "fmt"
-
"bitbucket.org/lightcodelabs/caddy2"
)
@@ -11,36 +9,5 @@ func init() {
caddy2.RegisterModule(caddy2.Module{
Name: "http.responders.reverse_proxy",
New: func() (interface{}, error) { return new(LoadBalanced), nil },
- OnLoad: func(instances []interface{}, _ interface{}) (interface{}, error) {
- // we don't need to do anything with prior state because healthcheckers are
- // cleaned up in OnUnload.
- s := &State{
- HealthCheckers: []*HealthChecker{},
- }
-
- for _, i := range instances {
- lb := i.(*LoadBalanced)
-
- err := NewLoadBalancedReverseProxy(lb, s)
- if err != nil {
- return nil, err
- }
- }
-
- return s, nil
- },
- OnUnload: func(state interface{}) error {
- s, ok := state.(*State)
- if !ok {
- return fmt.Errorf("proxy OnLoad: prior state not expected proxy.State type")
- }
-
- // cleanup old healthcheckers
- for _, hc := range s.HealthCheckers {
- hc.Stop()
- }
-
- return nil
- },
})
}
diff --git a/modules/caddyhttp/reverseproxy/upstream.go b/modules/caddyhttp/reverseproxy/upstream.go
index b521d46..7e429f9 100755
--- a/modules/caddyhttp/reverseproxy/upstream.go
+++ b/modules/caddyhttp/reverseproxy/upstream.go
@@ -76,7 +76,7 @@ var (
)
// NewLoadBalancedReverseProxy returns a collection of Upstreams that are to be loadbalanced.
-func NewLoadBalancedReverseProxy(lb *LoadBalanced, state *State) error {
+func NewLoadBalancedReverseProxy(lb *LoadBalanced, state *State, ctx caddy2.Context) error {
// set defaults
if lb.NoHealthyUpstreamsMessage == "" {
lb.NoHealthyUpstreamsMessage = msgNoHealthyUpstreams
@@ -115,7 +115,7 @@ func NewLoadBalancedReverseProxy(lb *LoadBalanced, state *State) error {
if uc.CircuitBreaker != nil {
if _, err := caddy2.GetModule(cbModule); err == nil {
- val, err := caddy2.LoadModule(cbModule, uc.CircuitBreaker)
+ val, err := ctx.LoadModule(cbModule, uc.CircuitBreaker)
if err == nil {
cbv, ok := val.(CircuitBreaker)
if ok {