limit

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT, MIT Imports: 4 Imported by: 0

README

Gin Access Limit Middleware

Based on bu/gin-access-limit

Usage


package main

import (
    gin "github.com/andoma-go/gin"
    "github.com/andoma-go/gin-contrib/limit"
)

func main() {
    // create a Gin engine
    r := gin.Default()

    // this API is only accessible from Docker containers
    r.Use(limit.New("172.18.0.0/16"))

    // if need to specify serveral range of allowed sources, use comma to concatenate them
    // r.Use(limit.New("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

This section is empty.

Functions

func New

func New(CIDRs string, opts ...Option) 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

type Handler

type Handler func(c *gin.Context, remoteAddr, CIDRs string) bool

type Limit

type Limit struct {
	// contains filtered or unexported fields
}

type Option

type Option func(*Limit)

func WithHandler

func WithHandler(handler Handler) Option

WithHandler

Jump to

Keyboard shortcuts

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