From 0495040426e45f45420276299587ad0625214ec6 Mon Sep 17 00:00:00 2001 From: HazCod Date: Wed, 24 Apr 2019 09:14:08 +0200 Subject: [PATCH 1/2] Add gin-gonic example --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 6c4b6cf..7966404 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,15 @@ func HandleJson(w http.ResponseWriter, r *http.Request) { } ``` +Example with [gin](https://github.com/gin-gonic/gin) that uses [gin-adapter](https://github.com/gwatts/gin-adapter): +``` +func GetCSRFMiddleware() gin.HandlerFunc { + nextHandler, wrapper := adapter.New() + csrfHandler := nosurf.New(nextHandler) + return wrapper(csrfHandler) +} +``` + ### Contributing 0. Find an issue that bugs you / open a new one. From d217374e742c3ad589219e6729df2a93e17bfd33 Mon Sep 17 00:00:00 2001 From: HazCod Date: Wed, 24 Apr 2019 15:35:14 +0200 Subject: [PATCH 2/2] Move to examples --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7966404..a6cd35e 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,15 @@ func main() { } ``` +Example with [gin](https://github.com/gin-gonic/gin) that uses [gin-adapter](https://github.com/gwatts/gin-adapter): +``` +func GetCSRFMiddleware() gin.HandlerFunc { + nextHandler, wrapper := adapter.New() + csrfHandler := nosurf.New(nextHandler) + return wrapper(csrfHandler) +} +``` + ### Manual token verification In some cases the CSRF token may be send through a non standard way, e.g. a body or request is a JSON encoded message with one of the fields @@ -117,15 +126,6 @@ func HandleJson(w http.ResponseWriter, r *http.Request) { } ``` -Example with [gin](https://github.com/gin-gonic/gin) that uses [gin-adapter](https://github.com/gwatts/gin-adapter): -``` -func GetCSRFMiddleware() gin.HandlerFunc { - nextHandler, wrapper := adapter.New() - csrfHandler := nosurf.New(nextHandler) - return wrapper(csrfHandler) -} -``` - ### Contributing 0. Find an issue that bugs you / open a new one.