own the usage of reflection into the RegisterType

allowing the users to only pass instances of the interfaces
This commit is contained in:
Mohammed Al Sahaf
2022-06-14 20:51:58 +03:00
parent 52f43d2f4c
commit b825a10927
16 changed files with 50 additions and 61 deletions
@@ -27,7 +27,6 @@ import (
"net/netip"
"net/textproto"
"net/url"
"reflect"
"strconv"
"strings"
"sync"
@@ -47,17 +46,17 @@ import (
func init() {
caddy.RegisterModule(Handler{})
caddy.RegisterType("http.reverse_proxy.circuit_breakers", []reflect.Type{
reflect.TypeOf((*CircuitBreaker)(nil)).Elem(),
caddy.RegisterType("http.reverse_proxy.circuit_breakers", []interface{}{
(*CircuitBreaker)(nil),
})
caddy.RegisterType("http.reverse_proxy.selection_policies", []reflect.Type{
reflect.TypeOf((*Selector)(nil)).Elem(),
caddy.RegisterType("http.reverse_proxy.selection_policies", []interface{}{
(*Selector)(nil),
})
caddy.RegisterType("http.reverse_proxy.transport", []reflect.Type{
reflect.TypeOf((*http.RoundTripper)(nil)).Elem(),
caddy.RegisterType("http.reverse_proxy.transport", []interface{}{
(*http.RoundTripper)(nil),
})
caddy.RegisterType("http.reverse_proxy.upstreams", []reflect.Type{
reflect.TypeOf((*UpstreamSource)(nil)).Elem(),
caddy.RegisterType("http.reverse_proxy.upstreams", []interface{}{
(*UpstreamSource)(nil),
})
}