Documentation ¶
Index ¶
- Constants
- Variables
- func Count(ctx context.Context, key string) (int, error)
- func Increment(ctx context.Context, key string) error
- func MustCount(ctx context.Context, key string) int
- func MustIncrement(ctx context.Context, key string)
- func MustReset(ctx context.Context, key string)
- func Reset(ctx context.Context, key string) error
- type Config
- type ConfigKind
- func (k *ConfigKind) Delete(ctx context.Context, key interface{}) (*datastore.Key, error)
- func (k *ConfigKind) DeleteMatched(ctx context.Context, q *ConfigQuery) (int, error)
- func (k *ConfigKind) DeleteMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, error)
- func (k *ConfigKind) EnforceNamespace(ns string, b bool) *ConfigKind
- func (k *ConfigKind) Get(ctx context.Context, key interface{}) (*datastore.Key, *Config, error)
- func (k *ConfigKind) GetMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, []*Config, error)
- func (k *ConfigKind) MustDelete(ctx context.Context, key interface{}) *datastore.Key
- func (k *ConfigKind) MustDeleteMulti(ctx context.Context, keys interface{}) []*datastore.Key
- func (k *ConfigKind) MustGet(ctx context.Context, key interface{}) *Config
- func (k *ConfigKind) MustGetMulti(ctx context.Context, keys interface{}) []*Config
- func (k *ConfigKind) MustPut(ctx context.Context, ent *Config) *datastore.Key
- func (k *ConfigKind) MustPutMulti(ctx context.Context, ents []*Config) []*datastore.Key
- func (k *ConfigKind) MustReplace(ctx context.Context, ent *Config, replacer ConfigKindReplacer) (*datastore.Key, *Config)
- func (k *ConfigKind) MustReplaceMulti(ctx context.Context, ents []*Config, replacer ConfigKindReplacer) ([]*datastore.Key, []*Config)
- func (k *ConfigKind) Put(ctx context.Context, ent *Config) (*datastore.Key, error)
- func (k *ConfigKind) PutMulti(ctx context.Context, ents []*Config) ([]*datastore.Key, error)
- func (k *ConfigKind) Replace(ctx context.Context, ent *Config, replacer ConfigKindReplacer) (*datastore.Key, *Config, error)
- func (k *ConfigKind) ReplaceMulti(ctx context.Context, ents []*Config, replacer ConfigKindReplacer) ([]*datastore.Key, []*Config, error)
- func (k *ConfigKind) UseDefaultIfNil(b bool) *ConfigKind
- type ConfigKindReplacer
- type ConfigKindReplacerFunc
- type ConfigPagination
- type ConfigQuery
- func (q *ConfigQuery) Ancestor(a lazy.Value) *ConfigQuery
- func (q *ConfigQuery) Asc(name string) *ConfigQuery
- func (q *ConfigQuery) Count(ctx context.Context) (int, error)
- func (q *ConfigQuery) Desc(name string) *ConfigQuery
- func (q *ConfigQuery) End(value lazy.Value) *ConfigQuery
- func (q *ConfigQuery) Eq(name string, value lazy.Value) *ConfigQuery
- func (q *ConfigQuery) Ge(name string, value lazy.Value) *ConfigQuery
- func (q *ConfigQuery) GetAll(ctx context.Context) ([]*datastore.Key, []*Config, error)
- func (q *ConfigQuery) GetAllValues(ctx context.Context) ([]*Config, error)
- func (q *ConfigQuery) Gt(name string, value lazy.Value) *ConfigQuery
- func (q *ConfigQuery) Le(name string, value lazy.Value) *ConfigQuery
- func (q *ConfigQuery) Limit(n lazy.Value) *ConfigQuery
- func (q *ConfigQuery) Lt(name string, value lazy.Value) *ConfigQuery
- func (q *ConfigQuery) MustCount(ctx context.Context) int
- func (q *ConfigQuery) MustGetAll(ctx context.Context) ([]*datastore.Key, []*Config)
- func (q *ConfigQuery) MustGetAllValues(ctx context.Context) []*Config
- func (q *ConfigQuery) MustRun(ctx context.Context) *ConfigPagination
- func (q *ConfigQuery) Ne(name string, value lazy.Value) *ConfigQuery
- func (q *ConfigQuery) Run(ctx context.Context) (*ConfigPagination, error)
- func (q *ConfigQuery) Start(value lazy.Value) *ConfigQuery
- func (q *ConfigQuery) ViaKeys(k *ConfigKind) *ConfigQuery
- type Shard
- type ShardKind
- func (k *ShardKind) Delete(ctx context.Context, key interface{}) (*datastore.Key, error)
- func (k *ShardKind) DeleteMatched(ctx context.Context, q *ShardQuery) (int, error)
- func (k *ShardKind) DeleteMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, error)
- func (k *ShardKind) EnforceNamespace(ns string, b bool) *ShardKind
- func (k *ShardKind) Get(ctx context.Context, key interface{}) (*datastore.Key, *Shard, error)
- func (k *ShardKind) GetMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, []*Shard, error)
- func (k *ShardKind) MustDelete(ctx context.Context, key interface{}) *datastore.Key
- func (k *ShardKind) MustDeleteMulti(ctx context.Context, keys interface{}) []*datastore.Key
- func (k *ShardKind) MustGet(ctx context.Context, key interface{}) *Shard
- func (k *ShardKind) MustGetMulti(ctx context.Context, keys interface{}) []*Shard
- func (k *ShardKind) MustPut(ctx context.Context, ent *Shard) *datastore.Key
- func (k *ShardKind) MustPutMulti(ctx context.Context, ents []*Shard) []*datastore.Key
- func (k *ShardKind) MustReplace(ctx context.Context, ent *Shard, replacer ShardKindReplacer) (*datastore.Key, *Shard)
- func (k *ShardKind) MustReplaceMulti(ctx context.Context, ents []*Shard, replacer ShardKindReplacer) ([]*datastore.Key, []*Shard)
- func (k *ShardKind) Put(ctx context.Context, ent *Shard) (*datastore.Key, error)
- func (k *ShardKind) PutMulti(ctx context.Context, ents []*Shard) ([]*datastore.Key, error)
- func (k *ShardKind) Replace(ctx context.Context, ent *Shard, replacer ShardKindReplacer) (*datastore.Key, *Shard, error)
- func (k *ShardKind) ReplaceMulti(ctx context.Context, ents []*Shard, replacer ShardKindReplacer) ([]*datastore.Key, []*Shard, error)
- func (k *ShardKind) UseDefaultIfNil(b bool) *ShardKind
- type ShardKindReplacer
- type ShardKindReplacerFunc
- type ShardPagination
- type ShardQuery
- func (q *ShardQuery) Ancestor(a lazy.Value) *ShardQuery
- func (q *ShardQuery) Asc(name string) *ShardQuery
- func (q *ShardQuery) Count(ctx context.Context) (int, error)
- func (q *ShardQuery) Desc(name string) *ShardQuery
- func (q *ShardQuery) End(value lazy.Value) *ShardQuery
- func (q *ShardQuery) Eq(name string, value lazy.Value) *ShardQuery
- func (q *ShardQuery) Ge(name string, value lazy.Value) *ShardQuery
- func (q *ShardQuery) GetAll(ctx context.Context) ([]*datastore.Key, []*Shard, error)
- func (q *ShardQuery) GetAllValues(ctx context.Context) ([]*Shard, error)
- func (q *ShardQuery) Gt(name string, value lazy.Value) *ShardQuery
- func (q *ShardQuery) Le(name string, value lazy.Value) *ShardQuery
- func (q *ShardQuery) Limit(n lazy.Value) *ShardQuery
- func (q *ShardQuery) Lt(name string, value lazy.Value) *ShardQuery
- func (q *ShardQuery) MustCount(ctx context.Context) int
- func (q *ShardQuery) MustGetAll(ctx context.Context) ([]*datastore.Key, []*Shard)
- func (q *ShardQuery) MustGetAllValues(ctx context.Context) []*Shard
- func (q *ShardQuery) MustRun(ctx context.Context) *ShardPagination
- func (q *ShardQuery) Ne(name string, value lazy.Value) *ShardQuery
- func (q *ShardQuery) Run(ctx context.Context) (*ShardPagination, error)
- func (q *ShardQuery) Start(value lazy.Value) *ShardQuery
- func (q *ShardQuery) ViaKeys(k *ShardKind) *ShardQuery
Constants ¶
const ConfigKindLoggerKey = "ent.counter_config"
ConfigKindLoggerKey is a logger key name for the ent
const ConfigQueryLoggerKey = "ent.query.counter_config"
ConfigQueryLoggerKey is a logger key name for the ent
const ShardKindLoggerKey = "ent.counter_shared"
ShardKindLoggerKey is a logger key name for the ent
const ShardQueryLoggerKey = "ent.query.counter_shared"
ShardQueryLoggerKey is a logger key name for the ent
Variables ¶
var DefaultConfigKind = &ConfigKind{}
DefaultConfigKind is a default value of *ConfigKind
var DefaultShardKind = &ShardKind{}
DefaultShardKind is a default value of *ShardKind
Functions ¶
func MustIncrement ¶
MustIncrement is like Increment but panics if an error occurrs.
Types ¶
type Config ¶
type Config struct { Key string `json:"key" ent:"id"` NumShards int `json:"num_shareds"` UpdatedAt time.Time `json:"updated_at" ent:"timestamp"` }
Config is a counter shard configuration
func NewConfig ¶
func NewConfig() *Config
NewConfig returns a new *Config with default field values.
func (*Config) UpdateByForm ¶
UpdateByForm updates the fields by form values. All values should be validated before calling this function.
type ConfigKind ¶
type ConfigKind struct {
// contains filtered or unexported fields
}
func (*ConfigKind) DeleteMatched ¶
func (k *ConfigKind) DeleteMatched(ctx context.Context, q *ConfigQuery) (int, error)
DeleteMatched deletes the all ents that match with the query. This func modify Limit/StartKey condition in the query so that you should restore it if you want to reuse the query.
func (*ConfigKind) DeleteMulti ¶
DeleteMulti do Delete with multiple keys
func (*ConfigKind) EnforceNamespace ¶
func (k *ConfigKind) EnforceNamespace(ns string, b bool) *ConfigKind
EnforceNamespace enforces namespace for Get/Put/Delete or not.
func (*ConfigKind) GetMulti ¶
func (k *ConfigKind) GetMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, []*Config, error)
GetMulti do Get with multiple keys. keys must be []string, []*datastore.Key, or []interface{}
func (*ConfigKind) MustDelete ¶
func (k *ConfigKind) MustDelete(ctx context.Context, key interface{}) *datastore.Key
MustDelete is like Delete but panic if an error occurs
func (*ConfigKind) MustDeleteMulti ¶
func (k *ConfigKind) MustDeleteMulti(ctx context.Context, keys interface{}) []*datastore.Key
MustDeleteMulti is like DeleteMulti but panic if an error occurs
func (*ConfigKind) MustGet ¶
func (k *ConfigKind) MustGet(ctx context.Context, key interface{}) *Config
MustGet is like Get but returns only values and panic if error happens.
func (*ConfigKind) MustGetMulti ¶
func (k *ConfigKind) MustGetMulti(ctx context.Context, keys interface{}) []*Config
MustGetMulti is like GetMulti but returns only values and panic if error happens.
func (*ConfigKind) MustPutMulti ¶
MustPutMulti is like PutMulti but panic if an error occurs
func (*ConfigKind) MustReplace ¶
func (k *ConfigKind) MustReplace(ctx context.Context, ent *Config, replacer ConfigKindReplacer) (*datastore.Key, *Config)
func (*ConfigKind) MustReplaceMulti ¶
func (k *ConfigKind) MustReplaceMulti(ctx context.Context, ents []*Config, replacer ConfigKindReplacer) ([]*datastore.Key, []*Config)
func (*ConfigKind) Replace ¶
func (k *ConfigKind) Replace(ctx context.Context, ent *Config, replacer ConfigKindReplacer) (*datastore.Key, *Config, error)
func (*ConfigKind) ReplaceMulti ¶
func (k *ConfigKind) ReplaceMulti(ctx context.Context, ents []*Config, replacer ConfigKindReplacer) ([]*datastore.Key, []*Config, error)
func (*ConfigKind) UseDefaultIfNil ¶
func (k *ConfigKind) UseDefaultIfNil(b bool) *ConfigKind
type ConfigKindReplacer ¶
type ConfigKindReplacerFunc ¶
type ConfigPagination ¶
type ConfigQuery ¶
type ConfigQuery struct {
// contains filtered or unexported fields
}
ConfigQuery helps to build and execute a query
func NewConfigQuery ¶
func NewConfigQuery() *ConfigQuery
func (*ConfigQuery) Ancestor ¶
func (q *ConfigQuery) Ancestor(a lazy.Value) *ConfigQuery
Ancestor sets the ancestor filter
func (*ConfigQuery) Asc ¶
func (q *ConfigQuery) Asc(name string) *ConfigQuery
Asc specifies ascending order on the given filed.
func (*ConfigQuery) Count ¶
func (q *ConfigQuery) Count(ctx context.Context) (int, error)
Count returns the count of entities
func (*ConfigQuery) Desc ¶
func (q *ConfigQuery) Desc(name string) *ConfigQuery
Desc specifies descending order on the given filed.
func (*ConfigQuery) End ¶
func (q *ConfigQuery) End(value lazy.Value) *ConfigQuery
Limit specifies the numbe of limit returend by this query.
func (*ConfigQuery) Eq ¶
func (q *ConfigQuery) Eq(name string, value lazy.Value) *ConfigQuery
Eq sets the "=" filter on the name field.
func (*ConfigQuery) Ge ¶
func (q *ConfigQuery) Ge(name string, value lazy.Value) *ConfigQuery
Ge sets the ">=" filter on the "name" field.
func (*ConfigQuery) GetAllValues ¶
func (q *ConfigQuery) GetAllValues(ctx context.Context) ([]*Config, error)
GetAllValues is like GetAll but returns only values
func (*ConfigQuery) Gt ¶
func (q *ConfigQuery) Gt(name string, value lazy.Value) *ConfigQuery
Gt sets the ">" filter on the "name" field.
func (*ConfigQuery) Le ¶
func (q *ConfigQuery) Le(name string, value lazy.Value) *ConfigQuery
Le sets the "<=" filter on the "name" field.
func (*ConfigQuery) Limit ¶
func (q *ConfigQuery) Limit(n lazy.Value) *ConfigQuery
Limit specifies the numbe of limit returend by this query.
func (*ConfigQuery) Lt ¶
func (q *ConfigQuery) Lt(name string, value lazy.Value) *ConfigQuery
Lt sets the "<" filter on the "name" field.
func (*ConfigQuery) MustCount ¶
func (q *ConfigQuery) MustCount(ctx context.Context) int
MustCount returns the count of entities
func (*ConfigQuery) MustGetAll ¶
MustGetAll is like GetAll but panic if an error occurrs.
func (*ConfigQuery) MustGetAllValues ¶
func (q *ConfigQuery) MustGetAllValues(ctx context.Context) []*Config
MustGetAllValues is like GetAllValues but panic if an error occurrs
func (*ConfigQuery) MustRun ¶
func (q *ConfigQuery) MustRun(ctx context.Context) *ConfigPagination
MustRun is like Run but panic if an error occurrs
func (*ConfigQuery) Ne ¶
func (q *ConfigQuery) Ne(name string, value lazy.Value) *ConfigQuery
Ne sets the "!=" filter on the "name" field.
func (*ConfigQuery) Run ¶
func (q *ConfigQuery) Run(ctx context.Context) (*ConfigPagination, error)
Run returns the a result as *ConfigPagination object
func (*ConfigQuery) Start ¶
func (q *ConfigQuery) Start(value lazy.Value) *ConfigQuery
Limit specifies the numbe of limit returend by this query.
func (*ConfigQuery) ViaKeys ¶
func (q *ConfigQuery) ViaKeys(k *ConfigKind) *ConfigQuery
ViaKeys optimize to execute keys-only query then call k.GetMulti() to fetch values. This would reduce the datastore query and maximize the memcache usage if the query called many times in a short time window.
type Shard ¶
type Shard struct { Key string `json:"key" ent:"id"` CounterKey string `json:"counter_key"` Count int `json:"count"` UpdatedAt time.Time `json:"updated_at" ent:"timestamp"` }
Shard is a counter shard.
func (*Shard) UpdateByForm ¶
UpdateByForm updates the fields by form values. All values should be validated before calling this function.
type ShardKind ¶
type ShardKind struct {
// contains filtered or unexported fields
}
func (*ShardKind) DeleteMatched ¶
DeleteMatched deletes the all ents that match with the query. This func modify Limit/StartKey condition in the query so that you should restore it if you want to reuse the query.
func (*ShardKind) DeleteMulti ¶
DeleteMulti do Delete with multiple keys
func (*ShardKind) EnforceNamespace ¶
EnforceNamespace enforces namespace for Get/Put/Delete or not.
func (*ShardKind) GetMulti ¶
func (k *ShardKind) GetMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, []*Shard, error)
GetMulti do Get with multiple keys. keys must be []string, []*datastore.Key, or []interface{}
func (*ShardKind) MustDelete ¶
MustDelete is like Delete but panic if an error occurs
func (*ShardKind) MustDeleteMulti ¶
MustDeleteMulti is like DeleteMulti but panic if an error occurs
func (*ShardKind) MustGetMulti ¶
MustGetMulti is like GetMulti but returns only values and panic if error happens.
func (*ShardKind) MustPutMulti ¶
MustPutMulti is like PutMulti but panic if an error occurs
func (*ShardKind) MustReplace ¶
func (*ShardKind) MustReplaceMulti ¶
func (*ShardKind) ReplaceMulti ¶
func (*ShardKind) UseDefaultIfNil ¶
type ShardKindReplacer ¶
type ShardKindReplacerFunc ¶
type ShardPagination ¶
type ShardQuery ¶
type ShardQuery struct {
// contains filtered or unexported fields
}
ShardQuery helps to build and execute a query
func NewShardQuery ¶
func NewShardQuery() *ShardQuery
func (*ShardQuery) Ancestor ¶
func (q *ShardQuery) Ancestor(a lazy.Value) *ShardQuery
Ancestor sets the ancestor filter
func (*ShardQuery) Asc ¶
func (q *ShardQuery) Asc(name string) *ShardQuery
Asc specifies ascending order on the given filed.
func (*ShardQuery) Count ¶
func (q *ShardQuery) Count(ctx context.Context) (int, error)
Count returns the count of entities
func (*ShardQuery) Desc ¶
func (q *ShardQuery) Desc(name string) *ShardQuery
Desc specifies descending order on the given filed.
func (*ShardQuery) End ¶
func (q *ShardQuery) End(value lazy.Value) *ShardQuery
Limit specifies the numbe of limit returend by this query.
func (*ShardQuery) Eq ¶
func (q *ShardQuery) Eq(name string, value lazy.Value) *ShardQuery
Eq sets the "=" filter on the name field.
func (*ShardQuery) Ge ¶
func (q *ShardQuery) Ge(name string, value lazy.Value) *ShardQuery
Ge sets the ">=" filter on the "name" field.
func (*ShardQuery) GetAllValues ¶
func (q *ShardQuery) GetAllValues(ctx context.Context) ([]*Shard, error)
GetAllValues is like GetAll but returns only values
func (*ShardQuery) Gt ¶
func (q *ShardQuery) Gt(name string, value lazy.Value) *ShardQuery
Gt sets the ">" filter on the "name" field.
func (*ShardQuery) Le ¶
func (q *ShardQuery) Le(name string, value lazy.Value) *ShardQuery
Le sets the "<=" filter on the "name" field.
func (*ShardQuery) Limit ¶
func (q *ShardQuery) Limit(n lazy.Value) *ShardQuery
Limit specifies the numbe of limit returend by this query.
func (*ShardQuery) Lt ¶
func (q *ShardQuery) Lt(name string, value lazy.Value) *ShardQuery
Lt sets the "<" filter on the "name" field.
func (*ShardQuery) MustCount ¶
func (q *ShardQuery) MustCount(ctx context.Context) int
MustCount returns the count of entities
func (*ShardQuery) MustGetAll ¶
MustGetAll is like GetAll but panic if an error occurrs.
func (*ShardQuery) MustGetAllValues ¶
func (q *ShardQuery) MustGetAllValues(ctx context.Context) []*Shard
MustGetAllValues is like GetAllValues but panic if an error occurrs
func (*ShardQuery) MustRun ¶
func (q *ShardQuery) MustRun(ctx context.Context) *ShardPagination
MustRun is like Run but panic if an error occurrs
func (*ShardQuery) Ne ¶
func (q *ShardQuery) Ne(name string, value lazy.Value) *ShardQuery
Ne sets the "!=" filter on the "name" field.
func (*ShardQuery) Run ¶
func (q *ShardQuery) Run(ctx context.Context) (*ShardPagination, error)
Run returns the a result as *ShardPagination object
func (*ShardQuery) Start ¶
func (q *ShardQuery) Start(value lazy.Value) *ShardQuery
Limit specifies the numbe of limit returend by this query.
func (*ShardQuery) ViaKeys ¶
func (q *ShardQuery) ViaKeys(k *ShardKind) *ShardQuery
ViaKeys optimize to execute keys-only query then call k.GetMulti() to fetch values. This would reduce the datastore query and maximize the memcache usage if the query called many times in a short time window.