Documentation ¶
Overview ¶
Package api exports a simple API to use a dcounter server.
package main import ( "fmt" "github.com/atomx/dcounter/api" ) func main() { d, err := dcounter.Dial("tcp", "127.0.0.1:9374") if err != nil { panic(err) } d.Inc("test", 1.2) fmt.Println(d.Get("test")) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API interface { // Ping pings the server and returns nil if everything is ok. Ping() error // Get returns the value of the counter, // a bool indicating if the cluster is stable. Get(id string) (float64, bool, error) // Inc increments or decrements (diff is negative) a counter. // The new value is returned. Inc(id string, diff float64) (float64, error) // Set sets the value of a counter. // Set is a heavy operation as it propagates using TCP. // Set returns once the value is propagated to all servers. // If set returns an error the change might have already been // propagated to some servers. // Set returns the old value. Set(id string, value float64) (float64, error) // List returns a map with all counters. List() (map[string]float64, error) // Join discards all data in the server and joines a cluster. Join(hosts []string) error // Save returns a json string containing the data for this server. // The json can be saved to a file and loaded using --load when starting a server. Save() (string, error) // Members returns a list of members of the current cluster. Members() ([]Member, error) // Close closes any open connection. // After close any function will just reopen the connection. Close() error }
API is the interface returned by New and Dial. This is an interface so you can easily mock this interface in your tests. API is NOT goroutine safe!
Click to show internal directories.
Click to hide internal directories.