Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins): Introduce go-zero plugin support #208

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/plugins-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.17
-
name: Checkout code
uses: actions/checkout@v2
Expand Down
59 changes: 52 additions & 7 deletions .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.17
-
name: Checkout code
uses: actions/checkout@v2
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
name: Wait for Souin is really loaded inside Echo as middleware
uses: jakejarvis/wait-action@master
with:
time: 30s
time: 20s
-
name: Set Echo logs configuration result as environment variable
run: cd plugins/echo/examples && echo "ECHO_MIDDLEWARE_RESULT=$(docker-compose logs echo | grep Souin)" >> $GITHUB_ENV
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
name: Wait for Souin is really loaded inside Chi as middleware
uses: jakejarvis/wait-action@master
with:
time: 30s
time: 20s
-
name: Set Chi logs configuration result as environment variable
run: cd plugins/chi/examples && echo "CHI_MIDDLEWARE_RESULT=$(docker-compose logs chi | grep Souin)" >> $GITHUB_ENV
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
name: Wait for Souin is really loaded inside Fiber as middleware
uses: jakejarvis/wait-action@master
with:
time: 30s
time: 40s
-
name: Set Fiber logs configuration result as environment variable
run: cd plugins/fiber/examples && echo "FIBER_MIDDLEWARE_RESULT=$(docker-compose logs fiber | grep Souin)" >> $GITHUB_ENV
Expand Down Expand Up @@ -191,7 +191,7 @@ jobs:
name: Wait for Souin is really loaded inside Gin as middleware
uses: jakejarvis/wait-action@master
with:
time: 30s
time: 20s
-
name: Set Gin logs configuration result as environment variable
run: cd plugins/gin/examples && echo "GIN_MIDDLEWARE_RESULT=$(docker-compose logs gin | grep Souin)" >> $GITHUB_ENV
Expand All @@ -210,6 +210,51 @@ jobs:
folder: Gin
reporters: cli
delayRequest: 5000
build-go-zero-validator:
name: Check that Souin build as Go-zero middleware
runs-on: ubuntu-latest
steps:
-
name: Add domain.com host to /etc/hosts
run: |
sudo echo "127.0.0.1 domain.com" | sudo tee -a /etc/hosts
-
name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16
-
name: Checkout code
uses: actions/checkout@v2
-
name: Install goctl
run: go install github.com/zeromicro/go-zero/tools/goctl@latest
-
name: Build Souin as Go-zero plugin
run: make build-and-run-go-zero
-
name: Wait for Souin is really loaded inside Go-zero as middleware
uses: jakejarvis/wait-action@master
with:
time: 50s
-
name: Set Go-zero logs configuration result as environment variable
run: cd plugins/go-zero/examples && echo "GO_ZERO_MIDDLEWARE_RESULT=$(docker-compose logs go-zero | grep Souin)" >> $GITHUB_ENV
-
name: Check if the configuration is loaded to define if Souin is loaded too
uses: nick-invision/assert-action@v1
with:
expected: '"message":"Souin configuration is now loaded."'
actual: ${{ env.GO_ZERO_MIDDLEWARE_RESULT }}
comparison: contains
-
name: Run Go-zero E2E tests
uses: anthonyvscode/newman-action@v1
with:
collection: "docs/e2e/Souin E2E.postman_collection.json"
folder: Go-zero
reporters: cli
delayRequest: 5000
build-goyave-validator:
name: Check that Souin build as Goyave middleware
runs-on: ubuntu-latest
Expand All @@ -233,7 +278,7 @@ jobs:
name: Wait for Souin is really loaded inside Goyave as middleware
uses: jakejarvis/wait-action@master
with:
time: 30s
time: 20s
-
name: Set Goyave logs configuration result as environment variable
run: cd plugins/goyave/examples && echo "GOYAVE_MIDDLEWARE_RESULT=$(docker-compose logs goyave | grep Souin)" >> $GITHUB_ENV
Expand Down Expand Up @@ -449,7 +494,7 @@ jobs:
name: Wait for Souin is really loaded inside Webgo as middleware
uses: jakejarvis/wait-action@master
with:
time: 30s
time: 20s
-
name: Set Webgo logs configuration result as environment variable
run: cd plugins/webgo/examples && echo "WEBGO_MIDDLEWARE_RESULT=$(docker-compose logs webgo | grep Souin)" >> $GITHUB_ENV
Expand Down
61 changes: 24 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
.PHONY: build-and-run-caddy build-and-run-caddy-json build-and-run-chi build-and-run-dotweb build-and-run-echo build-and-run-fiber \
build-and-run-gin build-and-run-goyave build-and-run-skipper build-and-run-souin build-and-run-traefik build-and-run-tyk \
build-and-run-webgo build-app build-caddy build-dev bump-version coverage create-network down env-dev env-prod gatling \
generate-plantUML golangci-lint health-check-prod help lint log tests up validate vendor-plugins
build-and-run-gin build-and-run-go-zero build-and-run-goyave build-and-run-skipper build-and-run-souin build-and-run-traefik \
build-and-run-tyk build-and-run-webgo build-app build-caddy build-dev bump-version coverage create-network down env-dev \
env-prod gatling generate-plantUML golangci-lint health-check-prod help lint log tests up validate vendor-plugins

DC=docker-compose
DC_BUILD=$(DC) build
DC_EXEC=$(DC) exec
PLUGINS_LIST=caddy chi dotweb echo fiber skipper gin go-zero goyave traefik tyk webgo

base-build-and-run-%:
cd plugins/$* && $(MAKE) prepare

build-and-run-caddy: ## Run caddy binary with the Caddyfile configuration
$(MAKE) build-caddy
Expand All @@ -15,38 +19,29 @@ build-and-run-caddy-json: ## Run caddy binary with the json configuration
$(MAKE) build-caddy
cd plugins/caddy && ./caddy run --config ./configuration.json

build-and-run-chi: ## Run Chi with Souin as plugin
cd plugins/chi && $(MAKE) prepare
build-and-run-chi: base-build-and-run-chi ## Run Chi with Souin as plugin

build-and-run-dotweb: base-build-and-run-dotweb ## Run Dotweb with Souin as plugin

build-and-run-dotweb: ## Run Dotweb with Souin as plugin
cd plugins/dotweb && $(MAKE) prepare
build-and-run-echo: base-build-and-run-echo ## Run Echo with Souin as plugin

build-and-run-echo: ## Run Echo with Souin as plugin
cd plugins/echo && $(MAKE) prepare
build-and-run-fiber: base-build-and-run-fiber ## Run Fiber with Souin as plugin

build-and-run-fiber: ## Run Fiber with Souin as plugin
cd plugins/fiber && $(MAKE) prepare
build-and-run-skipper: base-build-and-run-skipper ## Run Skipper with Souin as plugin

build-and-run-skipper: ## Run Skipper with Souin as plugin
cd plugins/skipper && $(MAKE) prepare
build-and-run-souin: base-build-and-run-souin ## Run Souin as plugin

build-and-run-souin: ## Run Souin as plugin
cd plugins/souin && $(MAKE) prepare
build-and-run-gin: base-build-and-run-gin ## Run Gin with Souin as plugin

build-and-run-gin: ## Run Gin with Souin as plugin
cd plugins/gin && $(MAKE) prepare
build-and-run-go-zero: base-build-and-run-go-zero ## Run Gin with Souin as plugin

build-and-run-goyave: ## Run Goyave with Souin as plugin
cd plugins/goyave && $(MAKE) prepare
build-and-run-goyave: base-build-and-run-goyave ## Run Goyave with Souin as plugin

build-and-run-traefik: ## Run træfik with Souin as plugin
cd plugins/traefik && $(MAKE) prepare
build-and-run-traefik: base-build-and-run-traefik ## Run træfik with Souin as plugin

build-and-run-tyk: ## Run tyk with Souin as middleware
cd plugins/tyk && $(MAKE) prepare
build-and-run-tyk: base-build-and-run-tyk ## Run tyk with Souin as middleware

build-and-run-webgo: ## Run Webgo with Souin as plugin
cd plugins/webgo && $(MAKE) prepare
build-and-run-webgo: base-build-and-run-webgo ## Run Webgo with Souin as plugin

build-app: env-prod ## Build containers with prod env vars
$(DC_BUILD) souin
Expand All @@ -64,7 +59,7 @@ build-dev: env-dev ## Build containers with dev env vars

bump-version:
sed -i '' 's/version: $(from)/version: $(to)/' README.md
for plugin in caddy chi dotweb echo fiber skipper gin goyave traefik tyk webgo ; do \
for plugin in $(PLUGINS_LIST) ; do \
sed -i '' 's/github.com\/darkweak\/souin $(from)/github.com\/darkweak\/souin $(to)/' plugins/$$plugin/go.mod ; \
done

Expand Down Expand Up @@ -116,15 +111,7 @@ up: ## Up containers
validate: lint tests down health-check-prod ## Run lint, tests and ensure prod can build

vendor-plugins: ## Generate and prepare vendors for each plugin
cd plugins/chi && $(MAKE) vendor
cd plugins/dotweb && $(MAKE) vendor
cd plugins/echo && $(MAKE) vendor
cd plugins/fiber && $(MAKE) vendor
cd plugins/gin && $(MAKE) vendor
cd plugins/goyave && $(MAKE) vendor
cd plugins/skipper && $(MAKE) vendor
cd plugins/souin && $(MAKE) vendor
cd plugins/tyk && $(MAKE) vendor
cd plugins/webgo && $(MAKE) vendor
cd plugins/traefik && $(MAKE) vendor
for plugin in $(PLUGINS_LIST) ; do \
cd plugins/$$plugin && ($(MAKE) vendor || true) && cd -; \
done
cd plugins/caddy && go mod tidy && go mod download
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
8.4. [Echo middleware](#echo-middleware)
8.5. [Fiber middleware](#fiber-middleware)
8.6. [Gin middleware](#gin-middleware)
8.7. [Goyave middleware](#goyave-middleware)
8.8. [Skipper filter](#skipper-filter)
8.9. [Træfik plugin](#træfik-plugin)
8.10. [Tyk plugin](#tyk-plugin)
8.11. [Webgo middleware](#webgo-middleware)
8.12. [Prestashop plugin](#prestashop-plugin)
8.13. [Wordpress plugin](#wordpress-plugin)
8.7. [Go-zero middleware](#go-zero-middleware)
8.8. [Goyave middleware](#goyave-middleware)
8.9. [Skipper filter](#skipper-filter)
8.10. [Træfik plugin](#træfik-plugin)
8.11. [Tyk plugin](#tyk-plugin)
8.12. [Webgo middleware](#webgo-middleware)
8.13. [Prestashop plugin](#prestashop-plugin)
8.14. [Wordpress plugin](#wordpress-plugin)
9. [Credits](#credits)

[![Travis CI](https://travis-ci.com/Darkweak/Souin.svg?branch=master)](https://travis-ci.com/Darkweak/Souin)
Expand Down Expand Up @@ -562,6 +563,26 @@ func main(){
}
```

### Go-zero middleware
To use Souin as go-zero middleware, you can refer to the [Go-zero plugin integration folder](https://github.com/darkweak/souin/tree/master/plugins/go-zero) to discover how to configure it.
You just have to give a Condfiguration object to the `NewHTTPCache` method to get a new HTTP cache instance and use the Handle method as a GlobalMiddleware:
```go
import (
"net/http"

cache "github.com/darkweak/souin/plugins/go-zero"
)

func main(){

// ...
httpcache := cache.NewHTTPCache(cache.DevDefaultConfiguration)
server.Use(httpcache.Handle)
// ...

}
```

### Goyave middleware
To use Souin as goyave middleware, you can refer to the [Goyave plugin integration folder](https://github.com/darkweak/souin/tree/master/plugins/goyave) to discover how to configure it.
You just have to start Goyave, define a new goyave router and tell to the router instance to use the Handle method as GlobalMiddleware like below:
Expand Down
Loading