Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

air-gases/limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Limiter

PkgGoDev

A useful gas that used to limit every request for the web applications built using Air.

Installation

Open your terminal and execute

$ go get github.com/air-gases/limiter

done.

The only requirement is the Go, at least v1.13.

Usage

The following application will limit the body size of all requests to within 1 MB.

package main

import (
	"github.com/air-gases/limiter"
	"github.com/aofei/air"
)

func main() {
	a := air.Default
	a.DebugMode = true
	a.Pregases = []air.Gas{
		limiter.BodySizeGas(limiter.BodySizeGasConfig{
			MaxBytes: 1 << 20,
		}),
	}
	a.GET("/", func(req *air.Request, res *air.Response) error {
		return res.WriteString("You are within the limits.")
	})
	a.Serve()
}

Community

If you want to discuss Limiter, or ask questions about it, simply post questions or ideas here.

Contributing

If you want to help build Limiter, simply follow this to send pull requests here.

License

This project is licensed under the MIT License.

License can be found here.