Skip to content

Commit

Permalink
Merge pull request #42 from ulule/feat/gomod
Browse files Browse the repository at this point in the history
Add go module
  • Loading branch information
novln authored Nov 5, 2018
2 parents d40ef3e + 1026e04 commit 14a36fd
Show file tree
Hide file tree
Showing 28 changed files with 147 additions and 186 deletions.
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ jobs:
name: Run tests
command: scripts/go-wrapper scripts/test
environment:
GO111MODULE: on
REDIS_DISABLE_BOOTSTRAP: false
REDIS_URI: redis://localhost:26379/1

- run:
name: Run linters
command: scripts/go-wrapper scripts/lint
no_output_timeout: 10m
environment:
GO111MODULE: on
103 changes: 0 additions & 103 deletions Gopkg.lock

This file was deleted.

18 changes: 0 additions & 18 deletions Gopkg.toml

This file was deleted.

7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
.PHONY: test
.PHONY: test lint

cleandb:
@(redis-cli KEYS "limitertests:*" | xargs redis-cli DEL)

test: cleandb
test:
@(scripts/test)

lint:
Expand Down
2 changes: 1 addition & 1 deletion drivers/middleware/gin/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gin-gonic/gin"

"github.com/ulule/limiter"
"github.com/ulule/limiter/v3"
)

// Middleware is the middleware for basic http.Handler.
Expand Down
6 changes: 3 additions & 3 deletions drivers/middleware/gin/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
libgin "github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"

"github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/middleware/gin"
"github.com/ulule/limiter/drivers/store/memory"
"github.com/ulule/limiter/v3"
"github.com/ulule/limiter/v3/drivers/middleware/gin"
"github.com/ulule/limiter/v3/drivers/store/memory"
)

func TestHTTPMiddleware(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/middleware/stdlib/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"strconv"

"github.com/ulule/limiter"
"github.com/ulule/limiter/v3"
)

// Middleware is the middleware for basic http.Handler.
Expand Down
6 changes: 3 additions & 3 deletions drivers/middleware/stdlib/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"github.com/stretchr/testify/require"

"github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/middleware/stdlib"
"github.com/ulule/limiter/drivers/store/memory"
"github.com/ulule/limiter/v3"
"github.com/ulule/limiter/v3/drivers/middleware/stdlib"
"github.com/ulule/limiter/v3/drivers/store/memory"
)

func TestHTTPMiddleware(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/store/common/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package common
import (
"time"

"github.com/ulule/limiter"
"github.com/ulule/limiter/v3"
)

// GetContextFromState generate a new limiter.Context from given state.
Expand Down
2 changes: 1 addition & 1 deletion drivers/store/memory/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/ulule/limiter/drivers/store/memory"
"github.com/ulule/limiter/v3/drivers/store/memory"
)

func TestCacheIncrementSequential(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/store/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

"github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/store/common"
"github.com/ulule/limiter/v3"
"github.com/ulule/limiter/v3/drivers/store/common"
)

// Store is the in-memory store.
Expand Down
6 changes: 3 additions & 3 deletions drivers/store/memory/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"testing"
"time"

"github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/store/memory"
"github.com/ulule/limiter/drivers/store/tests"
"github.com/ulule/limiter/v3"
"github.com/ulule/limiter/v3/drivers/store/memory"
"github.com/ulule/limiter/v3/drivers/store/tests"
)

func TestMemoryStoreSequentialAccess(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/store/redis/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
libredis "github.com/go-redis/redis"
"github.com/pkg/errors"

"github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/store/common"
"github.com/ulule/limiter/v3"
"github.com/ulule/limiter/v3/drivers/store/common"
)

// Client is an interface thats allows to use a redis cluster or a redis single client seamlessly.
Expand Down
6 changes: 3 additions & 3 deletions drivers/store/redis/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
libredis "github.com/go-redis/redis"
"github.com/stretchr/testify/require"

"github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/store/redis"
"github.com/ulule/limiter/drivers/store/tests"
"github.com/ulule/limiter/v3"
"github.com/ulule/limiter/v3/drivers/store/redis"
"github.com/ulule/limiter/v3/drivers/store/tests"
)

func TestRedisStoreSequentialAccess(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/store/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/ulule/limiter"
"github.com/ulule/limiter/v3"
)

// TestStoreSequentialAccess verify that store works as expected with a sequential access.
Expand Down
15 changes: 9 additions & 6 deletions examples/beego/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package main

/*
More comprehensive example:
More comprehensive example:
https://gist.github.com/gadelkareem/5a087bfda1f673241d0ac65759156cfd
*/
import (
"github.com/astaxie/beego"
"github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/store/memory"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/logs"
"github.com/ulule/limiter/v3"
"github.com/ulule/limiter/v3/drivers/store/memory"
"net"
"net/http"
"strconv"
"strings"
"github.com/astaxie/beego/logs"
)

type rateLimiter struct {
Expand Down Expand Up @@ -47,15 +49,16 @@ func main() {
func rateLimit(r *rateLimiter, ctx *context.Context) {
var (
limiterCtx limiter.Context
ip net.IP
err error
req = ctx.Request
)

ip := limiter.GetIP(req, false)

if strings.HasPrefix(ctx.Input.URL(), "/login") {
ip = r.loginLimiter.GetIP(req)
limiterCtx, err = r.loginLimiter.Get(req.Context(), ip.String())
} else {
ip = r.generalLimiter.GetIP(req)
limiterCtx, err = r.generalLimiter.Get(req.Context(), ip.String())
}
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions examples/chi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"github.com/go-chi/chi"
redis "github.com/go-redis/redis"
"github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/middleware/stdlib"
sredis "github.com/ulule/limiter/drivers/store/redis"
"github.com/ulule/limiter/v3"
"github.com/ulule/limiter/v3/drivers/middleware/stdlib"
sredis "github.com/ulule/limiter/v3/drivers/store/redis"
)

func main() {
Expand Down Expand Up @@ -40,7 +40,7 @@ func main() {
}

// Create a new middleware with the limiter instance.
middleware := stdlib.NewMiddleware(limiter.New(store, rate), stdlib.WithForwardHeader(true))
middleware := stdlib.NewMiddleware(limiter.New(store, rate, limiter.WithTrustForwardHeader(true)))

// Launch a simple chi server.
router := chi.NewRouter()
Expand Down
6 changes: 3 additions & 3 deletions examples/gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/gin-gonic/gin"
"github.com/go-redis/redis"
"github.com/ulule/limiter"
mgin "github.com/ulule/limiter/drivers/middleware/gin"
sredis "github.com/ulule/limiter/drivers/store/redis"
"github.com/ulule/limiter/v3"
mgin "github.com/ulule/limiter/v3/drivers/middleware/gin"
sredis "github.com/ulule/limiter/v3/drivers/store/redis"
)

func main() {
Expand Down
8 changes: 4 additions & 4 deletions examples/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"net/http"

redis "github.com/go-redis/redis"
"github.com/ulule/limiter"
"github.com/ulule/limiter/drivers/middleware/stdlib"
sredis "github.com/ulule/limiter/drivers/store/redis"
"github.com/ulule/limiter/v3"
"github.com/ulule/limiter/v3/drivers/middleware/stdlib"
sredis "github.com/ulule/limiter/v3/drivers/store/redis"
)

func main() {
Expand Down Expand Up @@ -39,7 +39,7 @@ func main() {
}

// Create a new middleware with the limiter instance.
middleware := stdlib.NewMiddleware(limiter.New(store, rate), stdlib.WithForwardHeader(true))
middleware := stdlib.NewMiddleware(limiter.New(store, rate, limiter.WithTrustForwardHeader(true)))

// Launch a simple server.
http.Handle("/", middleware.Handler(http.HandlerFunc(index)))
Expand Down
23 changes: 23 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module github.com/ulule/limiter/v3

require (
github.com/astaxie/beego v1.10.0
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect
github.com/gin-gonic/gin v1.3.0
github.com/go-chi/chi v3.3.3+incompatible
github.com/go-redis/redis v6.14.0+incompatible
github.com/json-iterator/go v0.0.0-20180806060727-1624edc4454b // indirect
github.com/mattn/go-isatty v0.0.3 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
github.com/onsi/gomega v1.4.2 // indirect
github.com/pkg/errors v0.8.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2
github.com/ugorji/go v1.1.1 // indirect
golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac // indirect
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v8 v8.18.2 // indirect
)
Loading

0 comments on commit 14a36fd

Please sign in to comment.