Peter Kurfer
671958e123
- HTTPS configuration is till missing - fix a few minor things in other plugins - cleanup of config to reduce repeating of the same values multiple times
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"gopkg.in/elazarl/goproxy.v1"
|
|
"net/http"
|
|
)
|
|
|
|
const (
|
|
passthroughStrategyName = "passthrough"
|
|
notFoundStrategyName = "notfound"
|
|
)
|
|
|
|
var (
|
|
fallbackStrategies map[string]ProxyFallbackStrategy
|
|
)
|
|
|
|
func init() {
|
|
fallbackStrategies = map[string]ProxyFallbackStrategy{
|
|
passthroughStrategyName: &passthroughFallbackStrategy{},
|
|
notFoundStrategyName: ¬FoundFallbackStrategy{},
|
|
}
|
|
}
|
|
|
|
func StrategyForName(name string) ProxyFallbackStrategy {
|
|
if strategy, ok := fallbackStrategies[name]; ok {
|
|
return strategy
|
|
}
|
|
return fallbackStrategies[notFoundStrategyName]
|
|
}
|
|
|
|
type ProxyFallbackStrategy interface {
|
|
Apply(request *http.Request) (*http.Response, error)
|
|
}
|
|
|
|
type passthroughFallbackStrategy struct {
|
|
}
|
|
|
|
func (p passthroughFallbackStrategy) Apply(request *http.Request) (*http.Response, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
type notFoundFallbackStrategy struct {
|
|
}
|
|
|
|
func (n notFoundFallbackStrategy) Apply(request *http.Request) (response *http.Response, err error) {
|
|
response = goproxy.NewResponse(
|
|
request,
|
|
goproxy.ContentTypeText,
|
|
http.StatusNotFound,
|
|
"The requested resource was not found",
|
|
)
|
|
return
|
|
}
|