Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 961 Bytes

README.md

File metadata and controls

64 lines (52 loc) · 961 Bytes

limit

-- import "github.com/sicuni/limit"

Usage

func InitLimit

func InitLimit() *Limit

InitLimit returns Initialize the constraint structure

func Exists

func (c *Limit) Exists(key interface{}) bool

Exists returns whether the key has a limit, if not add a limit

func Delete

func (c *Limit) Delete(key interface{})

Delete restrictions on the key

Type Limit

type Limit struct {
	sync.Mutex
	LimitKeyMap map[interface{}]int64
}

Test

package limit

import (
	"fmt"
	"testing"
)

func TestInitLimit(t *testing.T) {
	limit := InitLimit()

	str := "111"
if limit.Exists(str) {
		fmt.Println("limit str:", str)
	}
	// 此处被limit
if limit.Exists(str) {
		fmt.Println("limit str:", str)
	}

	key := 0
if limit.Exists(key) {
		fmt.Println("limit key:", key)
	}
	limit.Delete(key) // 解除限制
if limit.Exists(key) {
		fmt.Println("limit key:", key)
	}
}