counter

package
v0.0.0-...-ed9fe1d Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigKindLoggerKey = "ent.counter_config"

ConfigKindLoggerKey is a logger key name for the ent

View Source
const ConfigQueryLoggerKey = "ent.query.counter_config"

ConfigQueryLoggerKey is a logger key name for the ent

View Source
const ShardKindLoggerKey = "ent.counter_shared"

ShardKindLoggerKey is a logger key name for the ent

View Source
const ShardQueryLoggerKey = "ent.query.counter_shared"

ShardQueryLoggerKey is a logger key name for the ent

Variables

View Source
var DefaultConfigKind = &ConfigKind{}

DefaultConfigKind is a default value of *ConfigKind

View Source
var DefaultShardKind = &ShardKind{}

DefaultShardKind is a default value of *ShardKind

Functions

func Count

func Count(ctx context.Context, key string) (int, error)

Count returns the count value of the given key.

func Increment

func Increment(ctx context.Context, key string) error

Increment increments the counter of the given key

func MustCount

func MustCount(ctx context.Context, key string) int

MustCount is like Count but panics if an error occurrs.

func MustIncrement

func MustIncrement(ctx context.Context, key string)

MustIncrement is like Increment but panics if an error occurrs.

func MustReset

func MustReset(ctx context.Context, key string)

MustReset is like Reset but panics if an error occurrs.

func Reset

func Reset(ctx context.Context, key string) error

Reset resets the counter of the given key

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) NewKey

func (c *Config) NewKey(ctx context.Context) *datastore.Key

func (*Config) UpdateByForm

func (c *Config) UpdateByForm(form *keyvalue.GetProxy)

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) Delete

func (k *ConfigKind) Delete(ctx context.Context, key interface{}) (*datastore.Key, error)

Delete deletes the entity from datastore

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

func (k *ConfigKind) DeleteMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, error)

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) Get

func (k *ConfigKind) Get(ctx context.Context, key interface{}) (*datastore.Key, *Config, error)

Get gets the kind entity from datastore

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) MustPut

func (k *ConfigKind) MustPut(ctx context.Context, ent *Config) *datastore.Key

MustPut is like Put and panic if an error occurrs.

func (*ConfigKind) MustPutMulti

func (k *ConfigKind) MustPutMulti(ctx context.Context, ents []*Config) []*datastore.Key

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) Put

func (k *ConfigKind) Put(ctx context.Context, ent *Config) (*datastore.Key, error)

Put puts the entity to datastore.

func (*ConfigKind) PutMulti

func (k *ConfigKind) PutMulti(ctx context.Context, ents []*Config) ([]*datastore.Key, error)

PutMulti do Put with multiple keys

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 ConfigKindReplacer interface {
	Replace(*Config, *Config) *Config
}

type ConfigKindReplacerFunc

type ConfigKindReplacerFunc func(*Config, *Config) *Config

func (ConfigKindReplacerFunc) Replace

func (f ConfigKindReplacerFunc) Replace(ent1 *Config, ent2 *Config) *Config

type ConfigPagination

type ConfigPagination struct {
	Start string           `json:"start"`
	End   string           `json:"end"`
	Count int              `json:"count,omitempty"`
	Data  []*Config        `json:"data"`
	Keys  []*datastore.Key `json:"-"`
}

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) GetAll

func (q *ConfigQuery) GetAll(ctx context.Context) ([]*datastore.Key, []*Config, error)

GetAll returns all key and value of the query.

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

func (q *ConfigQuery) MustGetAll(ctx context.Context) ([]*datastore.Key, []*Config)

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

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 NewShard

func NewShard() *Shard

NewShard returns a new *Shard with default field values.

func (*Shard) NewKey

func (s *Shard) NewKey(ctx context.Context) *datastore.Key

func (*Shard) UpdateByForm

func (s *Shard) UpdateByForm(form *keyvalue.GetProxy)

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) Delete

func (k *ShardKind) Delete(ctx context.Context, key interface{}) (*datastore.Key, error)

Delete deletes the entity from datastore

func (*ShardKind) DeleteMatched

func (k *ShardKind) DeleteMatched(ctx context.Context, q *ShardQuery) (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 (*ShardKind) DeleteMulti

func (k *ShardKind) DeleteMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, error)

DeleteMulti do Delete with multiple keys

func (*ShardKind) EnforceNamespace

func (k *ShardKind) EnforceNamespace(ns string, b bool) *ShardKind

EnforceNamespace enforces namespace for Get/Put/Delete or not.

func (*ShardKind) Get

func (k *ShardKind) Get(ctx context.Context, key interface{}) (*datastore.Key, *Shard, error)

Get gets the kind entity from datastore

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

func (k *ShardKind) MustDelete(ctx context.Context, key interface{}) *datastore.Key

MustDelete is like Delete but panic if an error occurs

func (*ShardKind) MustDeleteMulti

func (k *ShardKind) MustDeleteMulti(ctx context.Context, keys interface{}) []*datastore.Key

MustDeleteMulti is like DeleteMulti but panic if an error occurs

func (*ShardKind) MustGet

func (k *ShardKind) MustGet(ctx context.Context, key interface{}) *Shard

MustGet is like Get but returns only values and panic if error happens.

func (*ShardKind) MustGetMulti

func (k *ShardKind) MustGetMulti(ctx context.Context, keys interface{}) []*Shard

MustGetMulti is like GetMulti but returns only values and panic if error happens.

func (*ShardKind) MustPut

func (k *ShardKind) MustPut(ctx context.Context, ent *Shard) *datastore.Key

MustPut is like Put and panic if an error occurrs.

func (*ShardKind) MustPutMulti

func (k *ShardKind) MustPutMulti(ctx context.Context, ents []*Shard) []*datastore.Key

MustPutMulti is like PutMulti but panic if an error occurs

func (*ShardKind) MustReplace

func (k *ShardKind) MustReplace(ctx context.Context, ent *Shard, replacer ShardKindReplacer) (*datastore.Key, *Shard)

func (*ShardKind) MustReplaceMulti

func (k *ShardKind) MustReplaceMulti(ctx context.Context, ents []*Shard, replacer ShardKindReplacer) ([]*datastore.Key, []*Shard)

func (*ShardKind) Put

func (k *ShardKind) Put(ctx context.Context, ent *Shard) (*datastore.Key, error)

Put puts the entity to datastore.

func (*ShardKind) PutMulti

func (k *ShardKind) PutMulti(ctx context.Context, ents []*Shard) ([]*datastore.Key, error)

PutMulti do Put with multiple keys

func (*ShardKind) Replace

func (k *ShardKind) Replace(ctx context.Context, ent *Shard, replacer ShardKindReplacer) (*datastore.Key, *Shard, error)

func (*ShardKind) ReplaceMulti

func (k *ShardKind) ReplaceMulti(ctx context.Context, ents []*Shard, replacer ShardKindReplacer) ([]*datastore.Key, []*Shard, error)

func (*ShardKind) UseDefaultIfNil

func (k *ShardKind) UseDefaultIfNil(b bool) *ShardKind

type ShardKindReplacer

type ShardKindReplacer interface {
	Replace(*Shard, *Shard) *Shard
}

type ShardKindReplacerFunc

type ShardKindReplacerFunc func(*Shard, *Shard) *Shard

func (ShardKindReplacerFunc) Replace

func (f ShardKindReplacerFunc) Replace(ent1 *Shard, ent2 *Shard) *Shard

type ShardPagination

type ShardPagination struct {
	Start string           `json:"start"`
	End   string           `json:"end"`
	Count int              `json:"count,omitempty"`
	Data  []*Shard         `json:"data"`
	Keys  []*datastore.Key `json:"-"`
}

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) GetAll

func (q *ShardQuery) GetAll(ctx context.Context) ([]*datastore.Key, []*Shard, error)

GetAll returns all key and value of the query.

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

func (q *ShardQuery) MustGetAll(ctx context.Context) ([]*datastore.Key, []*Shard)

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

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.

Jump to

Keyboard shortcuts

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