2016-06-06 11:51:56 +08:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mholt/caddy"
|
|
|
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-06-07 05:31:03 +08:00
|
|
|
caddy.RegisterPlugin("proxy", caddy.Plugin{
|
2016-06-06 11:51:56 +08:00
|
|
|
ServerType: "http",
|
|
|
|
Action: setup,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup configures a new Proxy middleware instance.
|
|
|
|
func setup(c *caddy.Controller) error {
|
|
|
|
upstreams, err := NewStaticUpstreams(c.Dispenser)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-06-21 01:44:20 +08:00
|
|
|
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
|
2016-06-06 11:51:56 +08:00
|
|
|
return Proxy{Next: next, Upstreams: upstreams}
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|