ratelimiter

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2018 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooBusy             = proto.ErrTooBusy
	ErrQuotaNotEnough      = proto.ErrQuotaNotEnough
	ErrExisted             = proto.ErrExisted
	ErrResourceNotRegisted = proto.ErrResourceNotRegisted
	ErrNoBorrowRecordFound = proto.ErrNoBorrowRecordFound
	ErrQuotaOverflow       = proto.ErrQuotaOverflow
)

Functions

This section is empty.

Types

type ClientConfig

type ClientConfig struct {
	// 服务端集群地址
	Cluster []string
}

客户端配置

type RateLimiterClient

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

RateLimiter服务客户端代理库

func New

func New(config *ClientConfig) (*RateLimiterClient, error)

func (*RateLimiterClient) Borrow

func (c *RateLimiterClient) Borrow(resourceType []byte, expire int64) (resourceId string, err error)

Borrow 借用资源 resourceType: 用户自定义资源类型 expire : 过期自动回收时间,单位秒。该时间建议与请求超时时间一致

func (*RateLimiterClient) BorrowWithTimeout

func (c *RateLimiterClient) BorrowWithTimeout(resourceType []byte, expire int64, timeout time.Duration) (resourceId string, err error)

BorrowWithTimeout 带超时的借用资源 @resourceType: 用户自定义资源类型 @expire : 过期自动回收时间,单位秒。该时间建议与请求超时时间一致

func (*RateLimiterClient) Close

func (c *RateLimiterClient) Close() error

Close 关闭limiter,释放该客户端占用的所有资源配额. 一般在程序退出时使用 注意:不调用Close操作会使得该客户端占用的资源持续占用直到超时。

func (*RateLimiterClient) DeleteQuota

func (c *RateLimiterClient) DeleteQuota(resourceType []byte) error

DeleteQuota 删除资源配额 resourceTypei : 用户自定义资源类型

func (*RateLimiterClient) RegistQuota

func (c *RateLimiterClient) RegistQuota(resourceType []byte, quota uint32, resetInterval int64) error

RegistQuota 注册资源配额 resourceTypei : 用户自定义资源类型 quota : 资源配额,例如quota为10表示限流10次/s resetInterval : 资源配额重置周期,单位秒

func (*RateLimiterClient) ResourceList

func (c *RateLimiterClient) ResourceList(rcType []byte) ([]*proto.APIResourceDetail, error)

ResourceList 查询资源列表 rcType : 资源类型,如果不填则表示全量查询

func (*RateLimiterClient) Return

func (c *RateLimiterClient) Return(resourceId string) error

Return 归还资源 resourceType: 用户自定义资源类型 resourceId : 要归还的资源ID

Jump to

Keyboard shortcuts

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