Documentation
¶
Index ¶
- Constants
- Variables
- func LimitsEmpty(l *ratelimits.ApiLimits) bool
- type Cache
- type RedisCache
- func (rl *RedisCache) CacheCheckInTime(ctx context.Context, t *time.Time, tid, id string) error
- func (rl *RedisCache) CacheLimits(ctx context.Context, l ratelimits.ApiLimits, tid, id, idtype string) error
- func (rl *RedisCache) CacheToken(ctx context.Context, tid, id, idtype, token string, expire time.Duration) error
- func (rl *RedisCache) DeleteToken(ctx context.Context, tid, id, idtype string) error
- func (rl *RedisCache) GetCheckInTime(ctx context.Context, tid, id string) (*time.Time, error)
- func (rl *RedisCache) GetCheckInTimes(ctx context.Context, tid string, ids []string) ([]*time.Time, error)
- func (rl *RedisCache) GetLimits(ctx context.Context, tid, id, idtype string) (*ratelimits.ApiLimits, error)
- func (rl *RedisCache) KeyBurst(tid, id, idtype, url, action, intvlNum string, version int) string
- func (rl *RedisCache) KeyCheckInTime(tid, id, idtype string, version int) string
- func (rl *RedisCache) KeyLimits(tid, id, idtype string, version int) string
- func (rl *RedisCache) KeyQuota(tid, id, idtype, intvlNum string, version int) string
- func (rl *RedisCache) KeyTenantVersion(tid string) string
- func (rl *RedisCache) KeyToken(tid, id, idtype string, version int) string
- func (rl *RedisCache) SuspendTenant(ctx context.Context, tid string) error
- func (rl *RedisCache) Throttle(ctx context.Context, rawToken string, l ratelimits.ApiLimits, ...) (string, error)
- func (rl *RedisCache) WithClock(c utils.Clock) *RedisCache
Constants ¶
View Source
const ( IdTypeDevice = "device" IdTypeUser = "user" // expiration of the device check in time - one week CheckInTimeExpiration = time.Duration(time.Hour * 24 * 7) )
Variables ¶
Functions ¶
func LimitsEmpty ¶
func LimitsEmpty(l *ratelimits.ApiLimits) bool
TODO: move to go-lib-micro/ratelimits
Types ¶
type Cache ¶
type Cache interface { // Throttle applies desired api limits and retrieves a cached token. // These ops are bundled because the implementation will pipeline them for a single network // roundtrip for max performance. // Returns: // - the token (if any) // - potentially ErrTooManyRequests (other errors: internal) Throttle( ctx context.Context, rawToken string, l ratelimits.ApiLimits, tid, id, idtype, url, action string, ) (string, error) // CacheToken caches the token under designated key, with expiration CacheToken(ctx context.Context, tid, id, idtype, token string, expireSec time.Duration) error // DeleteToken deletes the token for 'id' DeleteToken(ctx context.Context, tid, id, idtype string) error // GetLimits fetches limits for 'id' GetLimits(ctx context.Context, tid, id, idtype string) (*ratelimits.ApiLimits, error) // CacheLimits saves limits for 'id' CacheLimits(ctx context.Context, l ratelimits.ApiLimits, tid, id, idtype string) error // CacheCheckInTime caches the last device check in time CacheCheckInTime(ctx context.Context, t *time.Time, tid, id string) error // GetCheckInTime gets the last device check in time from cache GetCheckInTime(ctx context.Context, tid, id string) (*time.Time, error) // GetCheckInTimes gets the last device check in time from cache // for each device with id from the list of ids GetCheckInTimes(ctx context.Context, tid string, ids []string) ([]*time.Time, error) // SuspendTenant increment tenant key version // tenant key is used in all cache keys, this way, when we increment the key version, // all the keys are no longer accessible - in other words, be incrementing tenant key version // we invalidate all tenant keys SuspendTenant(ctx context.Context, tid string) error }
type RedisCache ¶
type RedisCache struct { LimitsExpireSec int // contains filtered or unexported fields }
func NewRedisCache ¶
func (*RedisCache) CacheCheckInTime ¶
func (*RedisCache) CacheLimits ¶
func (rl *RedisCache) CacheLimits( ctx context.Context, l ratelimits.ApiLimits, tid, id, idtype string, ) error
func (*RedisCache) CacheToken ¶
func (*RedisCache) DeleteToken ¶
func (rl *RedisCache) DeleteToken(ctx context.Context, tid, id, idtype string) error
func (*RedisCache) GetCheckInTime ¶
func (*RedisCache) GetCheckInTimes ¶
func (*RedisCache) GetLimits ¶
func (rl *RedisCache) GetLimits( ctx context.Context, tid, id, idtype string, ) (*ratelimits.ApiLimits, error)
func (*RedisCache) KeyBurst ¶
func (rl *RedisCache) KeyBurst( tid, id, idtype, url, action, intvlNum string, version int) string
func (*RedisCache) KeyCheckInTime ¶
func (rl *RedisCache) KeyCheckInTime(tid, id, idtype string, version int) string
func (*RedisCache) KeyLimits ¶
func (rl *RedisCache) KeyLimits(tid, id, idtype string, version int) string
func (*RedisCache) KeyQuota ¶
func (rl *RedisCache) KeyQuota(tid, id, idtype, intvlNum string, version int) string
func (*RedisCache) KeyTenantVersion ¶
func (rl *RedisCache) KeyTenantVersion(tid string) string
func (*RedisCache) KeyToken ¶
func (rl *RedisCache) KeyToken(tid, id, idtype string, version int) string
func (*RedisCache) SuspendTenant ¶
func (rl *RedisCache) SuspendTenant( ctx context.Context, tid string, ) error
func (*RedisCache) Throttle ¶
func (rl *RedisCache) Throttle( ctx context.Context, rawToken string, l ratelimits.ApiLimits, tid, id, idtype, url, action string, ) (string, error)
func (*RedisCache) WithClock ¶
func (rl *RedisCache) WithClock(c utils.Clock) *RedisCache
Click to show internal directories.
Click to hide internal directories.