Documentation ¶
Index ¶
- Variables
- type ClientConfig
- type RateLimiterClient
- func (c *RateLimiterClient) Borrow(resourceType []byte, expire int64) (resourceId string, err error)
- func (c *RateLimiterClient) BorrowWithTimeout(resourceType []byte, expire int64, timeout time.Duration) (resourceId string, err error)
- func (c *RateLimiterClient) Close() error
- func (c *RateLimiterClient) DeleteQuota(resourceType []byte) error
- func (c *RateLimiterClient) RegistQuota(resourceType []byte, quota uint32, resetInterval int64) error
- func (c *RateLimiterClient) ResourceList(rcType []byte) ([]*proto.APIResourceDetail, error)
- func (c *RateLimiterClient) Return(resourceId string) error
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 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
Click to show internal directories.
Click to hide internal directories.