accessLimit

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2020 License: MIT Imports: 4 Imported by: 2

README

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DisableLogging bool

DisableLogging set up logging. default is false (logging)

View Source
var TrustedHeaderField string

TrustedHeaderField is a header field that developer trusted in their env. e.g. Upstream proxy server's special header that only server can setup need to avoid use common forgry-able header fields.

Functions

func CIDR

func CIDR(CIDRs string) gin.HandlerFunc

CIDR is a middleware that check given CIDR rules and return 403 Forbidden when user is not coming from allowed source. CIDRs accepts a list of CIDRs, separated by comma. (e.g. 127.0.0.1/32, ::1/128 )

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL