fix(registry): log Unregister Close errors, add doc comments and 59 unit tests
Log close errors in Unregister instead of silently discarding them. Add doc comments to all exported symbols across 20 registry files. Add comprehensive tests covering base registry, all wrapper types, hot-reload delegation, nil-fallback semantics, and global accessors.
This commit is contained in:
@@ -9,14 +9,18 @@ import (
|
||||
"github.com/go-gost/core/limiter/traffic"
|
||||
)
|
||||
|
||||
// trafficLimiterRegistry implements a hot-reload-safe registry for traffic.TrafficLimiter.
|
||||
type trafficLimiterRegistry struct {
|
||||
registry[traffic.TrafficLimiter]
|
||||
}
|
||||
|
||||
// Register stores a TrafficLimiter under the given name.
|
||||
func (r *trafficLimiterRegistry) Register(name string, v traffic.TrafficLimiter) error {
|
||||
return r.registry.Register(name, v)
|
||||
}
|
||||
|
||||
// Get returns a wrapper that delegates to the currently registered TrafficLimiter.
|
||||
// Returns nil if name is empty.
|
||||
func (r *trafficLimiterRegistry) Get(name string) traffic.TrafficLimiter {
|
||||
if name != "" {
|
||||
return &trafficLimiterWrapper{name: name, r: r}
|
||||
@@ -49,14 +53,18 @@ func (w *trafficLimiterWrapper) Out(ctx context.Context, key string, opts ...lim
|
||||
return v.Out(ctx, key, opts...)
|
||||
}
|
||||
|
||||
// connLimiterRegistry implements a hot-reload-safe registry for conn.ConnLimiter.
|
||||
type connLimiterRegistry struct {
|
||||
registry[conn.ConnLimiter]
|
||||
}
|
||||
|
||||
// Register stores a ConnLimiter under the given name.
|
||||
func (r *connLimiterRegistry) Register(name string, v conn.ConnLimiter) error {
|
||||
return r.registry.Register(name, v)
|
||||
}
|
||||
|
||||
// Get returns a wrapper that delegates to the currently registered ConnLimiter.
|
||||
// Returns nil if name is empty.
|
||||
func (r *connLimiterRegistry) Get(name string) conn.ConnLimiter {
|
||||
if name != "" {
|
||||
return &connLimiterWrapper{name: name, r: r}
|
||||
@@ -81,14 +89,18 @@ func (w *connLimiterWrapper) Limiter(key string) conn.Limiter {
|
||||
return v.Limiter(key)
|
||||
}
|
||||
|
||||
// rateLimiterRegistry implements a hot-reload-safe registry for rate.RateLimiter.
|
||||
type rateLimiterRegistry struct {
|
||||
registry[rate.RateLimiter]
|
||||
}
|
||||
|
||||
// Register stores a RateLimiter under the given name.
|
||||
func (r *rateLimiterRegistry) Register(name string, v rate.RateLimiter) error {
|
||||
return r.registry.Register(name, v)
|
||||
}
|
||||
|
||||
// Get returns a wrapper that delegates to the currently registered RateLimiter.
|
||||
// Returns nil if name is empty.
|
||||
func (r *rateLimiterRegistry) Get(name string) rate.RateLimiter {
|
||||
if name != "" {
|
||||
return &rateLimiterWrapper{name: name, r: r}
|
||||
|
||||
Reference in New Issue
Block a user