Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bu/gin-access-limit
An IP source restriction middleware by specifying allowed source CIDR notations.
https://github.com/bu/gin-access-limit
accesscontrol cidr gin golang middleware restrictions
Last synced: 2 months ago
JSON representation
An IP source restriction middleware by specifying allowed source CIDR notations.
- Host: GitHub
- URL: https://github.com/bu/gin-access-limit
- Owner: bu
- License: mit
- Created: 2018-05-26T09:33:59.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2020-09-29T01:52:43.000Z (about 4 years ago)
- Last Synced: 2024-10-08T15:09:35.307Z (3 months ago)
- Topics: accesscontrol, cidr, gin, golang, middleware, restrictions
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 16
- Watchers: 2
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gin Access Limit Middleware
[![Go Report Card](https://goreportcard.com/badge/github.com/bu/gin-access-limit)](https://goreportcard.com/report/github.com/bu/gin-access-limit)
![Build Status](https://github.com/bu/gin-access-limit/workflows/build/badge.svg)
[![Documentation](https://godoc.org/github.com/bu/gin-access-limit?status.svg)](http://godoc.org/github.com/bu/gin-access-limit)A [Gin web framework](https://github.com/gin-gonic/gin) middleware for IP restriction by specifying CIDR notations.
## Usage
```go
package main
import (
gin "github.com/gin-gonic/gin"
limit "github.com/bu/gin-access-limit"
)func main() {
// create a Gin engine
r := gin.Default()// this API is only accessible from Docker containers
r.Use(limit.CIDR("172.18.0.0/16"))// if need to specify serveral range of allowed sources, use comma to concatenate them
// r.Use(limit.CIDR("172.18.0.0/16, 127.0.0.1/32"))// routes
r.GET("/", func (c *gin.Context) {
c.String(200, "pong")
})// listen to request
r.Run(":8080")
}```