mirror of
https://github.com/caddyserver/caddy.git
synced 2026-06-07 22:45:30 -04:00
own the usage of reflection into the RegisterType
allowing the users to only pass instances of the interfaces
This commit is contained in:
@@ -21,7 +21,6 @@ import (
|
||||
"fmt"
|
||||
weakrand "math/rand"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -34,11 +33,11 @@ import (
|
||||
func init() {
|
||||
caddy.RegisterModule(HTTPBasicAuth{})
|
||||
|
||||
caddy.RegisterType("http.authentication.hashes", []reflect.Type{
|
||||
reflect.TypeOf((*Comparer)(nil)).Elem(),
|
||||
caddy.RegisterType("http.authentication.hashes", []interface{}{
|
||||
(*Comparer)(nil),
|
||||
})
|
||||
caddy.RegisterType("http.authentication.providers", []reflect.Type{
|
||||
reflect.TypeOf((*Authenticator)(nil)).Elem(),
|
||||
caddy.RegisterType("http.authentication.providers", []interface{}{
|
||||
(*Authenticator)(nil),
|
||||
})
|
||||
|
||||
weakrand.Seed(time.Now().UnixNano())
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -38,8 +37,8 @@ import (
|
||||
|
||||
func init() {
|
||||
caddy.RegisterModule(Encode{})
|
||||
caddy.RegisterType("http.encoders", []reflect.Type{
|
||||
reflect.TypeOf((*Encoding)(nil)).Elem(),
|
||||
caddy.RegisterType("http.encoders", []interface{}{
|
||||
(*Encoding)(nil),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -42,8 +41,8 @@ import (
|
||||
func init() {
|
||||
weakrand.Seed(time.Now().UnixNano())
|
||||
|
||||
caddy.RegisterType("http.precompressed", []reflect.Type{
|
||||
reflect.TypeOf((*encode.Precompressed)(nil)).Elem(),
|
||||
caddy.RegisterType("http.precompressed", []interface{}{
|
||||
(*encode.Precompressed)(nil),
|
||||
})
|
||||
|
||||
caddy.RegisterModule(FileServer{})
|
||||
|
||||
@@ -214,8 +214,8 @@ func init() {
|
||||
caddy.RegisterModule(MatchHeaderRE{})
|
||||
caddy.RegisterModule(new(MatchProtocol))
|
||||
caddy.RegisterModule(MatchNot{})
|
||||
caddy.RegisterType("http.matchers", []reflect.Type{
|
||||
reflect.TypeOf((*RequestMatcher)(nil)).Elem(),
|
||||
caddy.RegisterType("http.matchers", []interface{}{
|
||||
(*RequestMatcher)(nil),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -18,14 +18,13 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterType("http.handlers", []reflect.Type{
|
||||
reflect.TypeOf((*MiddlewareHandler)(nil)).Elem(),
|
||||
caddy.RegisterType("http.handlers", []interface{}{
|
||||
(*MiddlewareHandler)(nil),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user