From 65ec89ff19d79cf7eaa668f12984ae1b4f47acde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Jochum?= Date: Fri, 23 Sep 2022 08:24:25 +0200 Subject: [PATCH] Auth is no more a WIP, Ratelimiter now uses memory:// by default --- README.md | 4 ---- cmd/microrouterd/handler/handler.go | 6 +++++- cmd/microrouterd/main.go | 3 ++- go.mod | 2 +- go.sum | 2 ++ 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ff9c167..d762bad 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,6 @@ A dynamic router (API Gatway) for go-micro. It looks for services that host "internal/proto/routerclientpb/routerclientpb.RouterClientService" and ask's them for routes/endpoints, then it registers that endpoints via a proxy method within gin. -## AUTH is WORK IN PROGRESS - -I'm still working on the implementation of jo-micro/auth2, everything Auth related my change. - ## Caveats - gin doesn't allow to delete routes, so if you want to delete a route you have to restart go-micro/router. diff --git a/cmd/microrouterd/handler/handler.go b/cmd/microrouterd/handler/handler.go index 6b32f3b..fd3bf34 100644 --- a/cmd/microrouterd/handler/handler.go +++ b/cmd/microrouterd/handler/handler.go @@ -8,11 +8,13 @@ import ( "io" "net/http" "strconv" + "strings" "time" libredis "github.com/go-redis/redis/v8" limiter "github.com/ulule/limiter/v3" + "github.com/ulule/limiter/v3/drivers/store/memory" sredis "github.com/ulule/limiter/v3/drivers/store/redis" "github.com/gin-gonic/gin" @@ -53,7 +55,7 @@ func (h *Handler) Init(service micro.Service, engine *gin.Engine, routerAuth aut h.routerAuth = routerAuth globalGroup := h.engine.Group("") - if rlStoreURL != "" { + if strings.HasPrefix(rlStoreURL, "redis://") { // Create a redis client. option, err := libredis.ParseURL(rlStoreURL) if err != nil { @@ -70,6 +72,8 @@ func (h *Handler) Init(service micro.Service, engine *gin.Engine, routerAuth aut return err } h.rlStore = store + } else if rlStoreURL == "memory://" { + h.rlStore = memory.NewStore() } // Refresh routes for the proxy every 10 seconds diff --git a/cmd/microrouterd/main.go b/cmd/microrouterd/main.go index 55806e8..64c33c1 100644 --- a/cmd/microrouterd/main.go +++ b/cmd/microrouterd/main.go @@ -116,8 +116,9 @@ func main() { }, &cli.StringFlag{ Name: "router_ratelimiter_store_url", - Usage: "Ratelimiter store URL, for example redis://localhost:6379/0. No store = no Endpoints that require a ratelimiter", + Usage: "Ratelimiter store URL, for example redis://localhost:6379/0", EnvVars: []string{"MICRO_ROUTER_RATELIMITER_STORE_URL"}, + Value: "memory://", }, }))) diff --git a/go.mod b/go.mod index 4f1a73a..844958e 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/urfave/cli/v2 v2.16.3 go-micro.dev/v4 v4.8.1 google.golang.org/protobuf v1.28.1 - jochum.dev/jo-micro/auth2 v0.3.1 + jochum.dev/jo-micro/auth2 v0.3.2 ) require ( diff --git a/go.sum b/go.sum index 55b8e23..bc968f7 100644 --- a/go.sum +++ b/go.sum @@ -313,3 +313,5 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= jochum.dev/jo-micro/auth2 v0.3.0 h1:7r9Vo7/Wlc/tB8sBN4BGQFniOy2x1ekoWI5I4+xBUv0= jochum.dev/jo-micro/auth2 v0.3.0/go.mod h1:fSWMvxDct/jhmP1CC5HQTSfklqZRmygO8Zv5qZVuUHg= jochum.dev/jo-micro/auth2 v0.3.1/go.mod h1:fSWMvxDct/jhmP1CC5HQTSfklqZRmygO8Zv5qZVuUHg= +jochum.dev/jo-micro/auth2 v0.3.2 h1:dWY7RPLS3/Sn7YWDz4Kl8Str6lzMXUdfbMBLJLXmehk= +jochum.dev/jo-micro/auth2 v0.3.2/go.mod h1:VRGDU1tsDrlEVN9ch3DlvhUslDTQGGp3KLReBRL6V1s=