main.go 655 B

1234567891011121314151617181920212223242526272829303132333435
  1. package ipblack
  2. import (
  3. "context"
  4. "time"
  5. "github.com/labring/aiproxy/core/common"
  6. log "github.com/sirupsen/logrus"
  7. )
  8. func SetIPBlackAnyWay(ip string, duration time.Duration) {
  9. if common.RedisEnabled {
  10. _, err := redisSetIPBlack(context.Background(), ip, duration)
  11. if err == nil {
  12. return
  13. }
  14. log.Errorf("failed to set IP %s black: %s", ip, err)
  15. }
  16. memSetIPBlack(ip, duration)
  17. }
  18. func GetIPIsBlockAnyWay(ctx context.Context, ip string) bool {
  19. if common.RedisEnabled {
  20. ok, err := redisGetIPIsBlock(ctx, ip)
  21. if err == nil {
  22. return ok
  23. }
  24. log.Errorf("failed to get IP %s is block: %s", ip, err)
  25. }
  26. return memGetIPIsBlock(ip)
  27. }