docs(limiter/conn): add doc comments, fix nil guards and missing Close
Add package and exported symbol doc comments across conn, generator, limiter, and wrapper packages. Fix nil receiver guard in connLimitSingleGenerator.Limiter, add missing httpLoader.Close call, return context.Background instead of nil in serverConn.Context, return explicit error on connection limit exceeded, and simplify Allow logic.
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
limiter "github.com/go-gost/core/limiter/conn"
|
||||
)
|
||||
|
||||
// ConnLimitGenerator creates individual Limiter instances for use in
|
||||
// per-IP or per-CIDR connection limiting.
|
||||
type ConnLimitGenerator interface {
|
||||
Limiter() limiter.Limiter
|
||||
}
|
||||
@@ -12,6 +14,8 @@ type connLimitGenerator struct {
|
||||
n int
|
||||
}
|
||||
|
||||
// NewConnLimitGenerator returns a ConnLimitGenerator that creates a new
|
||||
// Limiter on each call to Limiter(), using the given limit n.
|
||||
func NewConnLimitGenerator(n int) ConnLimitGenerator {
|
||||
return &connLimitGenerator{
|
||||
n: n,
|
||||
@@ -29,6 +33,8 @@ type connLimitSingleGenerator struct {
|
||||
limiter limiter.Limiter
|
||||
}
|
||||
|
||||
// NewConnLimitSingleGenerator returns a ConnLimitGenerator that always
|
||||
// returns the same Limiter instance, using the given limit n.
|
||||
func NewConnLimitSingleGenerator(n int) ConnLimitGenerator {
|
||||
p := &connLimitSingleGenerator{}
|
||||
if n > 0 {
|
||||
@@ -38,5 +44,8 @@ func NewConnLimitSingleGenerator(n int) ConnLimitGenerator {
|
||||
}
|
||||
|
||||
func (p *connLimitSingleGenerator) Limiter() limiter.Limiter {
|
||||
if p == nil {
|
||||
return nil
|
||||
}
|
||||
return p.limiter
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user