burst

package module
v0.0.0-...-f76c5b6 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 4 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Burst

Build Status

令牌桶限流器

基于 Golang 官方扩展包 golang.org/x/time/rate

⚙ Installation

go get -u github.com/eininst/fiber-middleware-burst

⚡ Quickstart

package main

import (
    burst "github.com/eininst/fiber-middleware-burst"
    "github.com/gofiber/fiber/v2"
    "golang.org/x/time/rate"
    "time"
)

func main() {
    app := fiber.New()

    app.Use(burst.New(burst.Config{
        //每秒产生200个令牌, 最多存储500个令牌。
        Limiter: rate.NewLimiter(200, 500),
        //拿不到令牌时等待3秒,仍拿不到则返回 "too many requests"
        Timeout: time.Second * 3,
    }))

    _ = app.Listen(":8080")
}

See examples

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg Config) fiber.Handler

Types

type Config

type Config struct {
	Limiter        *rate.Limiter
	Timeout        time.Duration
	TimeoutHandler fiber.Handler
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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