Logs for GlobalDeviceLimit

This commit is contained in:
AikoCute 2022-11-20 10:10:03 +07:00
parent 1897404c9d
commit 86324ff1ae

View File

@ -4,6 +4,7 @@ package limiter
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -47,6 +48,7 @@ func New() *Limiter {
func (l *Limiter) AddInboundLimiter(tag string, nodeSpeedLimit uint64, userList *[]api.UserInfo, globalDeviceLimit *GlobalDeviceLimitConfig) error { func (l *Limiter) AddInboundLimiter(tag string, nodeSpeedLimit uint64, userList *[]api.UserInfo, globalDeviceLimit *GlobalDeviceLimitConfig) error {
// global limit // global limit
if globalDeviceLimit.Limit > 0 { if globalDeviceLimit.Limit > 0 {
log.Printf("[%s] GlobalDeviceLimit limit: %d", tag, globalDeviceLimit.Limit)
l.r = redis.NewClient(&redis.Options{ l.r = redis.NewClient(&redis.Options{
Addr: globalDeviceLimit.RedisAddr, Addr: globalDeviceLimit.RedisAddr,
Password: globalDeviceLimit.RedisPassword, Password: globalDeviceLimit.RedisPassword,
@ -100,7 +102,7 @@ func (l *Limiter) UpdateInboundLimiter(tag string, updatedUserList *[]api.UserIn
} }
} }
} else { } else {
return fmt.Errorf("no such inbound in limiter: %s", tag) return newError("no such inbound in limiter: %s", tag).AtError()
} }
return nil return nil
} }
@ -135,7 +137,7 @@ func (l *Limiter) GetOnlineDevice(tag string) (*[]api.OnlineUser, error) {
return true return true
}) })
} else { } else {
return nil, fmt.Errorf("no such inbound in limiter: %s", tag) return nil, newError("no such inbound in limiter: %s", tag).AtError()
} }
return &onlineUser, nil return &onlineUser, nil
} }