aac139368f
Moves all packages from internal/ to pkg/ so they can be imported by external modules (needed for claude-pm integration). - internal/app/ → pkg/app/ - internal/docker/ → pkg/docker/ - internal/config/ → pkg/config/ - internal/utils/ → pkg/utils/ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
30 lines
438 B
Go
30 lines
438 B
Go
package utils
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type RateLimiter struct {
|
|
lastTime time.Time
|
|
minInterval time.Duration
|
|
}
|
|
|
|
func NewRateLimiter(interval time.Duration) *RateLimiter {
|
|
return &RateLimiter{
|
|
minInterval: interval,
|
|
}
|
|
}
|
|
|
|
func (r *RateLimiter) Allow() bool {
|
|
now := time.Now()
|
|
if now.Sub(r.lastTime) >= r.minInterval {
|
|
r.lastTime = now
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (r *RateLimiter) Reset() {
|
|
r.lastTime = time.Time{}
|
|
}
|