dcounter

package
v0.2.1-0...-a6904e9 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2015 License: MIT Imports: 5 Imported by: 3

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!

func Dial

func Dial(network, address string) (API, error)

Dial tries to connect and if successful returns a new API client.

func New

func New(network, address string) API

New returns a new API client but does not connect. The connection will be made when the first command is run.

type Member

type Member struct {
	Name string
	Addr net.IP
}

Jump to

Keyboard shortcuts

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