From e791e752b465f2944b96fcc49ea576800464bb2a Mon Sep 17 00:00:00 2001 From: Roman Kredentser Date: Thu, 9 Apr 2020 15:39:51 +0300 Subject: [PATCH] update deps --- go.mod | 3 ++- go.sum | 5 +++-- main.go | 14 +++++++------- main_test.go | 21 +++++++++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 main_test.go diff --git a/go.mod b/go.mod index a930fb4..b5217a0 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,6 @@ go 1.14 require ( github.com/go-redis/redis/v7 v7.2.0 github.com/gofiber/fiber v1.8.431 - github.com/shareed2k/go_limiter v0.0.5 + github.com/shareed2k/go_limiter v0.0.6 + github.com/stretchr/testify v1.5.1 ) diff --git a/go.sum b/go.sum index 74e5145..5e17279 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,9 @@ github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/shareed2k/go_limiter v0.0.5 h1:v6JhDd/rp5aGum4HYg7Ko0k/ATQtj91OXP0AsrWuGsY= -github.com/shareed2k/go_limiter v0.0.5/go.mod h1:YD+giVRK4A6t4OpIdsQP716pXuL2+Fp52B7LfyNI5m0= +github.com/shareed2k/go_limiter v0.0.6 h1:iySeSnJ17B4Xs7ctb5Cb5H/ogGbtT66L/GZoMEGFEjA= +github.com/shareed2k/go_limiter v0.0.6/go.mod h1:YD+giVRK4A6t4OpIdsQP716pXuL2+Fp52B7LfyNI5m0= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= diff --git a/main.go b/main.go index 63b6aa6..90bbba5 100644 --- a/main.go +++ b/main.go @@ -12,9 +12,9 @@ import ( ) const ( - SimpleAlgorithm = "simple" - GCRAAlgorithm = "gcra" - DefaultKeyPrefix = "fiber_limiter" + SlidingWindowAlgorithm = go_limiter.SlidingWindowAlgorithm + GCRAAlgorithm = go_limiter.GCRAAlgorithm + DefaultKeyPrefix = "fiber_limiter" ) // Config ... @@ -38,8 +38,8 @@ type Config struct { Message string // Algorithm - // Default: simple - Algorithm string + // Default: sliding window + Algorithm uint // Prefix // Default: @@ -99,8 +99,8 @@ func New(config Config) func(*fiber.Ctx) { } } - if config.Algorithm == "" { - config.Algorithm = SimpleAlgorithm + if config.Algorithm == 0 { + config.Algorithm = SlidingWindowAlgorithm } if config.Period == 0 { diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..6262f15 --- /dev/null +++ b/main_test.go @@ -0,0 +1,21 @@ +package fiber_limiter + +import ( + "testing" + + "github.com/gofiber/fiber" + "github.com/stretchr/testify/assert" +) + +func TestPanicOnNilRediser(t *testing.T) { + ff := func() { + New(Config{})(&fiber.Ctx{}) + } + + assert.Panics(t, ff, "should panic on rediser nil") +} + +func TestSkipOnError(t *testing.T) { + app := fiber.New() + +}