client

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConn    = errors.New("missing connection")
	ErrFailure = errors.New("request has failed")
	ErrKind    = errors.New("invalid data type")
)

Error messages.

View Source
var DefaultCacheDuration = 15 * time.Minute

DefaultCacheDuration is the default duration to keep data in cache.

Functions

This section is empty.

Types

type Asserter

type Asserter interface {
	Assert(value interface{}, typ Kind) (interface{}, bool)
}

Asserter must be implemented by any client that needs to assert its values.

type Cache

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

Cache represents the service to access data as a memory cache.

func NewCache

func NewCache(duration time.Duration) *Cache

NewCache returns a new instance of the cache and starts the recycler. The Close method must be called to properly close the recycler and avoids leaks.

func (*Cache) Close

func (c *Cache) Close() error

Close stops the ticker to clean the cache.

func (*Cache) Delete

func (c *Cache) Delete(key string) error

Delete removes the data behind the key in the cache.

func (*Cache) Get

func (c *Cache) Get(key string) interface{}

Get returns the value behind the key in cache.

func (*Cache) Lookup

func (c *Cache) Lookup(key string) (interface{}, bool)

Lookup returns the value behind the key in cache. If the key is not found, the boolean is false.

func (*Cache) NoExpiration

func (c *Cache) NoExpiration()

NoExpiration deactivates the item's expiration.

func (*Cache) Set

func (c *Cache) Set(key string, value interface{}) error

Set puts the value in cache with an expiration date fixed by the cache duration.

func (*Cache) UseExpiration

func (c *Cache) UseExpiration()

UseExpiration reactivates the item's expiration.

func (*Cache) WithExpiration

func (c *Cache) WithExpiration() bool

WithExpiration returns true if the data expiration is enabled.

type Caller

type Caller interface {
	Call(service string, args, reply interface{}) error
	Close() error
}

Caller must be implemented by any client to call a service, waits for it to complete, and returns its error status.

type Checker

type Checker interface {
	Available() bool
}

Checker must be implemented by any client to notify its availability.

type GetSetter

type GetSetter interface {
	Getter
	Setter
}

GetSetter must be implemented by any client to get and set data.

type Getter

type Getter interface {
	Lookup(key string) (interface{}, bool)
}

Getter must be implemented by any client to get data.

type Kind added in v0.0.2

type Kind int

Kind is the data type.

const (
	BoolVal Kind = 1 << iota
	FloatVal
	IntVal
	StringVal
)

List of value's kind.

type OS

type OS struct{}

OS is the client to get environment variable from operating system.

func (*OS) Assert

func (o *OS) Assert(value interface{}, typ Kind) (interface{}, bool)

Assert tries to cast the value with the given data kind. If success, it returns the data typed and true as ok value.

func (*OS) Get

func (o *OS) Get(key string) interface{}

Get retrieves the value of the environment variable named by the key.

func (*OS) Lookup

func (o *OS) Lookup(key string) (interface{}, bool)

Lookup gets the value of the environment variable named by the key. If the variable is present in the environment, the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.

func (*OS) Set

func (o *OS) Set(key string, value interface{}) error

Set sets the value of the environment variable named by the key.

type RPC

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

RPC is client with connection to cache'service.

func NewRPC

func NewRPC(conn Caller) *RPC

NewRPC returns a new instance of RPC. This instance has no mechanism to reconnect on failure.

func OpenRPC

func OpenRPC(dsn string, timeout time.Duration) (*RPC, error)

OpenRPC returns an instance of RPC with a TCP connection into it. DSN is in the form of "localhost:9090". If the connection fails, it returns the error. Unlike NewRPC, OpenRPC has an internal mechanism to reconnect on failure.

func (*RPC) Available

func (r *RPC) Available() bool

Available implements the Checker interface.

func (*RPC) Bulk

func (r *RPC) Bulk(batch map[string]interface{}) error

Bulk applies the item modifications on the cache. It acknowledges the boolean if it succeeds. An error occurs if the call fails.

func (*RPC) Clear

func (r *RPC) Clear() error

Clear resets the cache and acknowledges the boolean if it succeeds. An error occurs if the call fails.

func (*RPC) Close added in v0.0.9

func (r *RPC) Close() error

Close closes the connection.

func (*RPC) Delete

func (r *RPC) Delete(key string) error

Delete removes this key in the cache and acknowledges the boolean if it succeeds. An error occurs if the call fails.

func (*RPC) Get

func (r *RPC) Get(key string) interface{}

Get returns the value behind the key in the cache.

func (*RPC) Lookup

func (r *RPC) Lookup(key string) (interface{}, bool)

Lookup gets the value of the environment variable named by the key. If the variable is present in the environment, the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.

func (*RPC) Raw

func (r *RPC) Raw(key string) (interface{}, error)

Raw returns the value behind the key or an error if it not exists

func (*RPC) Set

func (r *RPC) Set(key string, value interface{}) error

Set saves the item and acknowledges the boolean if it succeeds. An error occurs if the call fails.

func (*RPC) Stats

func (r *RPC) Stats() (*cache.Metrics, error)

Stats returns statistics about the current server. An error occurs and returned if the call fails.

type Setter

type Setter interface {
	Set(key string, value interface{}) error
}

Setter must be implemented by any client to set data.

Jump to

Keyboard shortcuts

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