66 "sync"
77 "time"
88
9- "github.com/Narasimha1997/ratelimiter"
109 "github.com/chaitin/koalaqa/model"
1110 "github.com/chaitin/koalaqa/pkg/glog"
11+ "github.com/chaitin/koalaqa/pkg/ratelimit"
1212 "github.com/chaitin/koalaqa/pkg/webhook"
1313 "github.com/chaitin/koalaqa/pkg/webhook/message"
1414 "github.com/chaitin/koalaqa/repo"
@@ -19,7 +19,7 @@ type Webhook struct {
1919 logger * glog.Logger
2020 lock sync.Mutex
2121 webhooks map [uint ]webhook.Webhook
22- limiter * ratelimiter. AttributeBasedLimiter
22+ limiter ratelimit. Limiter
2323
2424 repoWebhook * repo.Webhook
2525}
@@ -125,7 +125,7 @@ func (w *Webhook) Delete(ctx context.Context, id uint) error {
125125}
126126
127127func (w * Webhook ) allow (id uint , discID string , msgType message.Type ) bool {
128- return w .limiter .MustShouldAllow (fmt .Sprintf ("webhook-%d-%s-%d" , id , discID , msgType ), 1 , 1 , time .Minute * 5 )
128+ return w .limiter .Allow (fmt .Sprintf ("webhook-%d-%s-%d" , id , discID , msgType ), time .Minute * 5 , 1 )
129129}
130130
131131func (w * Webhook ) Send (ctx context.Context , msg message.Message ) error {
@@ -143,12 +143,12 @@ func (w *Webhook) Send(ctx context.Context, msg message.Message) error {
143143 return nil
144144}
145145
146- func newWebhook (lc fx.Lifecycle , repoWebhook * repo.Webhook ) * Webhook {
146+ func newWebhook (lc fx.Lifecycle , repoWebhook * repo.Webhook , limiter ratelimit. Limiter ) * Webhook {
147147 w := & Webhook {
148148 logger : glog .Module ("svc" , "webhook" ),
149149 repoWebhook : repoWebhook ,
150150 webhooks : make (map [uint ]webhook.Webhook ),
151- limiter : ratelimiter . NewAttributeBasedLimiter ( false ) ,
151+ limiter : limiter ,
152152 }
153153 lc .Append (fx.Hook {
154154 OnStart : func (ctx context.Context ) error {
0 commit comments