Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joeig/gin-nonce
Nonce middleware for Gin
https://github.com/joeig/gin-nonce
csp gin go nonce
Last synced: about 1 month ago
JSON representation
Nonce middleware for Gin
- Host: GitHub
- URL: https://github.com/joeig/gin-nonce
- Owner: joeig
- License: mit
- Created: 2023-10-30T17:39:23.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-29T14:23:51.000Z (7 months ago)
- Last Synced: 2024-05-01T12:44:31.216Z (7 months ago)
- Topics: csp, gin, go, nonce
- Language: Go
- Homepage: https://pkg.go.dev/go.eigsys.de/gin-nonce
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nonce middleware for Gin
This Gin middleware generates a nonce for each request.
[![Test coverage](https://img.shields.io/badge/coverage-100%25-success)](https://github.com/joeig/gin-nonce/tree/main/.github/testcoverage.yml)
[![Go Report Card](https://goreportcard.com/badge/go.eigsys.de/gin-nonce)](https://goreportcard.com/report/go.eigsys.de/gin-nonce)
[![PkgGoDev](https://pkg.go.dev/badge/go.eigsys.de/gin-nonce)](https://pkg.go.dev/go.eigsys.de/gin-nonce)## Usage
```go
package mainimport (
"fmt"
"net/http"
"time""github.com/gin-gonic/gin"
"go.eigsys.de/gin-nonce"
)func main() {
router := gin.Default()handler := nonce.New()
router.Use(handler.Middleware())router.GET("/", func(ginCtx *gin.Context) {
currentNonce, _ := handler.GetNonce(ginCtx)
ginCtx.Header("Content-Security-Policy", fmt.Sprintf("style-src 'nonce-%s';", currentNonce))ginCtx.String(http.StatusOK, "Hello, Gopher!")
})_ = router.Run()
}
```## Documentation
See [Go reference](https://pkg.go.dev/go.eigsys.de/gin-nonce).