mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 12:16:16 +08:00
27 lines
561 B
Go
27 lines
561 B
Go
|
package proxy
|
||
|
|
||
|
import (
|
||
|
"github.com/mholt/caddy"
|
||
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
caddy.RegisterPlugin(caddy.Plugin{
|
||
|
Name: "proxy",
|
||
|
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
|
||
|
}
|
||
|
httpserver.GetConfig(c.Key).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
|
||
|
return Proxy{Next: next, Upstreams: upstreams}
|
||
|
})
|
||
|
return nil
|
||
|
}
|