access_limiter

package module
v0.0.0-...-303d6ce Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2015 License: Apache-2.0 Imports: 6 Imported by: 0

README

access_limiter

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ERR_QPS_REACHED_UPPER_LIMIT   = errors.TN(ACCESS_LIMITER_NS, 1, "qps reached upper limit, counter: {{.counter}}, {{.dimensions}}")
	ERR_QUOTA_REACHED_UPPER_LIMIT = errors.TN(ACCESS_LIMITER_NS, 2, "quota reached upper limit, counter: {{.counter}}, {{.dimensions}}")
	ERR_INCREASE_COUNT_FAILED     = errors.TN(ACCESS_LIMITER_NS, 3, "increase counter failed, counter: {{.counter}}, err: {{.err}}")
	ERR_INCREASE_QPS_COUNT_FAILED = errors.TN(ACCESS_LIMITER_NS, 4, "increase qps count failed, counter: {{.counter}}, err: {{.err}}")
	ERR_RESET_QPS_COUNT_FAILED    = errors.TN(ACCESS_LIMITER_NS, 5, "reset next qps count failed, counter: {{.counter}}, err: {{.err}}")
	ERR_RESET_COUNT_FAILED        = errors.TN(ACCESS_LIMITER_NS, 6, "reset counter failed, counter: {{.counter}}, err: {{.err}}")
	ERR_GET_OPTIONS_FAILED        = errors.TN(ACCESS_LIMITER_NS, 7, "get options failed, counter: {{.counter}}")
	ERR_UPDATE_OPTIONS_FAILED     = errors.TN(ACCESS_LIMITER_NS, 8, "update options failed, counter: {{.counter}}, err: {{.err}}")
)
View Source
var ACCESS_LIMITER_NS = "ACCESS_LIMITER"

Functions

This section is empty.

Types

type ClassicCounter

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

func (*ClassicCounter) Consume

func (p *ClassicCounter) Consume(count int64, dimensions ...string) (err error)

func (*ClassicCounter) ConsumeSpeed

func (p *ClassicCounter) ConsumeSpeed(dimensions ...string) (speed int64)

func (*ClassicCounter) GetOptions

func (p *ClassicCounter) GetOptions(dimensions ...string) (opts []CounterOption, err error)

func (*ClassicCounter) IsCanConsume

func (p *ClassicCounter) IsCanConsume(count int64, dimensions ...string) (isCan bool)

func (*ClassicCounter) Name

func (p *ClassicCounter) Name() (name string)

func (*ClassicCounter) Reset

func (p *ClassicCounter) Reset(dimensions ...string) (err error)

func (*ClassicCounter) UpdateOptions

func (p *ClassicCounter) UpdateOptions(opts []CounterOption, dimensions ...string) (err error)

type Counter

type Counter interface {
	Name() (name string)
	Consume(count int64, dimensions ...string) (err error)
	IsCanConsume(count int64, dimensions ...string) (isCan bool)
	Reset(dimensions ...string) (err error)
	ConsumeSpeed(dimensions ...string) (speed int64)
	UpdateOptions(opts []CounterOption, dimensions ...string) (err error)
	GetOptions(dimensions ...string) (opts []CounterOption, err error)
}

func NewClassicCounter

func NewClassicCounter(name string, storage CounterStorage) Counter

type CounterOption

type CounterOption struct {
	Name  OptionName
	Value string
}

type CounterStorage

type CounterStorage interface {
	Increase(counterName string, count, max int64, dimensions ...string) (err error)
	Delete(counterName string, dimensions ...string) (err error)
	SetValue(counterName string, value int64, dimensions ...string) (err error)
	GetValue(counterName string, dimensions ...string) (dimVal int64, exist bool)
	GetSumValue(counterName string, dimensionsGroup [][]string) (sumDimVal int64, err error)
	GetOptions(counterName, key string) (opts []CounterOption, exist bool)
	SetOptions(counterName, key string, opts ...CounterOption) (err error)
}

func NewMemoryCounterStorage

func NewMemoryCounterStorage() CounterStorage

func NewRedisCounterStorage

func NewRedisCounterStorage(config RedisConfig) CounterStorage

type MemoryCounterStorage

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

func (*MemoryCounterStorage) Delete

func (p *MemoryCounterStorage) Delete(counterName string, dimensions ...string) (err error)

func (*MemoryCounterStorage) GetOptions

func (p *MemoryCounterStorage) GetOptions(counterName, key string) (opts []CounterOption, exist bool)

func (*MemoryCounterStorage) GetSumValue

func (p *MemoryCounterStorage) GetSumValue(counterName string, dimensionsGroup [][]string) (sumDimVal int64, err error)

func (*MemoryCounterStorage) GetValue

func (p *MemoryCounterStorage) GetValue(counterName string, dimensions ...string) (dimVal int64, exist bool)

func (*MemoryCounterStorage) Increase

func (p *MemoryCounterStorage) Increase(counterName string, count, max int64, dimensions ...string) (err error)

func (*MemoryCounterStorage) SetOptions

func (p *MemoryCounterStorage) SetOptions(counterName, key string, opts ...CounterOption) (err error)

func (*MemoryCounterStorage) SetValue

func (p *MemoryCounterStorage) SetValue(counterName string, value int64, dimensions ...string) (err error)

type OptionName

type OptionName string
const (
	LimitQuotaOption OptionName = "limit_quota"
	LimitQPSOption              = "limit_qps"
)

type RedisConfig

type RedisConfig struct {
	IdleTimeout time.Duration
	MaxIdle     int
	MaxActive   int

	Address  string
	Password string
	Db       int

	Prefix string

	Transaction     bool
	ConsistentRetry int
}

type RedisCounterStorage

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

func (*RedisCounterStorage) Delete

func (p *RedisCounterStorage) Delete(counterName string, dimensions ...string) (err error)

func (*RedisCounterStorage) GetOptions

func (p *RedisCounterStorage) GetOptions(counterName, key string) (opts []CounterOption, exist bool)

func (*RedisCounterStorage) GetSumValue

func (p *RedisCounterStorage) GetSumValue(counterName string, dimensionsGroup [][]string) (sumDimVal int64, err error)

func (*RedisCounterStorage) GetValue

func (p *RedisCounterStorage) GetValue(counterName string, dimensions ...string) (dimVal int64, exist bool)

func (*RedisCounterStorage) Increase

func (p *RedisCounterStorage) Increase(counterName string, count, max int64, dimensions ...string) (err error)

func (*RedisCounterStorage) SetOptions

func (p *RedisCounterStorage) SetOptions(counterName, key string, opts ...CounterOption) (err error)

func (*RedisCounterStorage) SetValue

func (p *RedisCounterStorage) SetValue(counterName string, value int64, dimensions ...string) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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