Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bu/gin-access-limit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

22 Commits

Repository files navigation

Gin Access Limit Middleware

Go Report Card Build Status Documentation

A Gin web framework middleware for IP restriction by specifying CIDR notations.

Usage

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")
}

About

An IP source restriction middleware by specifying allowed source CIDR notations.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

Languages

AltStyle によって変換されたページ (->オリジナル) /