Skip to content

Commit

Permalink
feat(docs): Bump to prepare v1.6.3 (#195)
Browse files Browse the repository at this point in the history
* feat(docs): Bump to prepare v1.6.3

* feat(plugins): Introduce chi plugin (#196)

* fix(plugins): DefaultSouinPluginCallback return an error if necessary (#197)
  • Loading branch information
darkweak authored Mar 22, 2022
1 parent 04801fe commit 896cb46
Show file tree
Hide file tree
Showing 33 changed files with 1,444 additions and 125 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,48 @@ jobs:
folder: Echo
reporters: cli
delayRequest: 5000
build-chi-validator:
name: Check that Souin build as Chi 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: Build Souin as Chi plugin
run: make build-and-run-chi
-
name: Wait for Souin is really loaded inside Chi as middleware
uses: jakejarvis/wait-action@master
with:
time: 30s
-
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
-
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.CHI_MIDDLEWARE_RESULT }}
comparison: contains
-
name: Run Chi E2E tests
uses: anthonyvscode/newman-action@v1
with:
collection: "docs/e2e/Souin E2E.postman_collection.json"
folder: Chi
reporters: cli
delayRequest: 5000
build-gin-validator:
name: Check that Souin build as Gin middleware
runs-on: ubuntu-latest
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: build-and-run-caddy build-and-run-caddy-json build-and-run-echo build-and-run-gin build-and-run-skipper build-and-run-traefik \
build-and-run-tyk build-and-run-webgo build-app build-caddy build-dev coverage create-network down env-dev env-prod gatling generate-plantUML \
golangci-lint health-check-prod help lint log tests up validate vendor-plugins
.PHONY: build-and-run-caddy build-and-run-caddy-json build-and-run-chi build-and-run-echo build-and-run-gin build-and-run-skipper \
build-and-run-traefik build-and-run-tyk build-and-run-webgo build-app build-caddy build-dev 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
Expand All @@ -14,6 +14,9 @@ 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-echo: ## Run Echo with Souin as plugin
cd plugins/echo && $(MAKE) prepare

Expand Down Expand Up @@ -94,6 +97,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/echo && $(MAKE) vendor
cd plugins/gin && $(MAKE) vendor
cd plugins/skipper && $(MAKE) vendor
Expand Down
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
7.1. [Træfik container](#træfik-container)
8. [Plugins](#plugins)
8.1. [Caddy module](#caddy-module)
8.1. [Chi middleware](#chi-middleware)
8.3. [Echo middleware](#echo-middleware)
8.4. [Gin middleware](#gin-middleware)
8.5. [Skipper filter](#skipper-filter)
Expand Down Expand Up @@ -451,6 +452,29 @@ cache @matchdefault {
cache @souin-api {}
```

### Chi middleware
To use Souin as chi middleware, you can refer to the [Chi middleware integration folder](https://github.com/darkweak/souin/tree/master/plugins/chi) to discover how to configure it.
You just have to define a new chi router and tell to the instance to use the `Handle` method like below:
```go
import (
"net/http"
cache "github.com/darkweak/souin/plugins/chi"
"github.com/go-chi/chi/v5"
)
func main(){
// ...
router := chi.NewRouter()
httpcache := cache.NewHTTPCache(cache.DevDefaultConfiguration)
router.Use(httpcache.Handle)
router.Get("/*", defaultHandler)
// ...
}
```

### Echo middleware
To use Souin as echo middleware, you can refer to the [Echo plugin integration folder](https://github.com/darkweak/souin/tree/master/plugins/echo) to discover how to configure it.
You just have to define a new echo router and tell to the instance to use the process method like below:
Expand Down Expand Up @@ -532,7 +556,7 @@ experimental:
plugins:
souin:
moduleName: github.com/darkweak/souin
version: v1.6.2
version: v1.6.3
```
After that you can declare either the whole configuration at once in the middleware block or by service. See the examples below.
```yaml
Expand Down Expand Up @@ -598,7 +622,7 @@ services:
labels:
# other labels...
- traefik.http.routers.whoami.middlewares=http-cache
- traefik.http.middlewares.http-cache.plugin.souin-plugin.api.souin.enable=true
- traefik.http.middlewares.http-cache.plugin.souin-plugin.api.souin
- traefik.http.middlewares.http-cache.plugin.souin-plugin.default_cache.headers=Authorization,Content-Type
- traefik.http.middlewares.http-cache.plugin.souin-plugin.default_cache.ttl=10s
- traefik.http.middlewares.http-cache.plugin.souin-plugin.log_level=debug
Expand Down
4 changes: 2 additions & 2 deletions cache/coalescing/requestCoalescing.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func ServeResponse(
res http.ResponseWriter,
req *http.Request,
retriever types.RetrieverResponsePropertiesInterface,
callback func(http.ResponseWriter, *http.Request, types.RetrieverResponsePropertiesInterface, RequestCoalescingInterface, func(http.ResponseWriter, *http.Request) error),
callback func(http.ResponseWriter, *http.Request, types.RetrieverResponsePropertiesInterface, RequestCoalescingInterface, func(http.ResponseWriter, *http.Request) error) error,
rc RequestCoalescingInterface,
nm func(w http.ResponseWriter, r *http.Request) error,
) {
Expand All @@ -45,5 +45,5 @@ func ServeResponse(
}
}

callback(res, req, retriever, rc, nm)
_ = callback(res, req, retriever, rc, nm)
}
6 changes: 4 additions & 2 deletions cache/coalescing/requestCoalescing_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package coalescing

import (
"github.com/darkweak/souin/cache/surrogate"
"net/http"
"net/http/httptest"
"regexp"
"testing"

"github.com/darkweak/souin/cache/surrogate"

"github.com/darkweak/souin/cache/providers"
"github.com/darkweak/souin/cache/types"
"github.com/darkweak/souin/cache/ykeys"
Expand Down Expand Up @@ -50,7 +51,8 @@ func TestServeResponse(t *testing.T) {
types.RetrieverResponsePropertiesInterface,
RequestCoalescingInterface,
func(http.ResponseWriter, *http.Request) error,
) {
) error {
return nil
},
rc,
func(http.ResponseWriter, *http.Request) error {
Expand Down
Loading

0 comments on commit 896cb46

Please sign in to comment.