Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yuce committed Mar 14, 2017
1 parent a84a220 commit 2679dca
Show file tree
Hide file tree
Showing 14 changed files with 4,588 additions and 132 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Go Client for Pilosa

Go client for Pilosa high performance database.

## Changelog

* 2017-03-15: Initial version

## Requirements

* Go 1.8

## Install

```
go get github.com/pilosa/go-pilosa
```

## Usage

### Quick overview

**TODO**

## Contribution

### Running tests

You can run unit tests with:
```
$ go test
```

And integration tests with:

**TODO**

Run the tests with coverage:
```
$ go test -cover
```

### Generating protobuf classes

**TODO**

## License

**TODO**
53 changes: 53 additions & 0 deletions cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package pilosa

// ICluster contains the interface for Cluster implementations
type ICluster interface {
getAddress() *URI
removeAddress(address *URI)
}

// Cluster is a simple ICluster implementation
type Cluster struct {
addresses []*URI
nextIndex int
}

// NewCluster creates a Cluster with no addresses
func NewCluster() *Cluster {
return &Cluster{
addresses: make([]*URI, 0),
nextIndex: 0,
}
}

// NewClusterWithAddress creates a Cluster with the given address
func NewClusterWithAddress(address *URI) *Cluster {
cluster := NewCluster()
cluster.AddAddress(address)
return cluster
}

// AddAddress adds an address to the cluster
func (c *Cluster) AddAddress(address *URI) {
c.addresses = append(c.addresses, address)
}

// GetAddress returns the next address in the cluster
func (c *Cluster) GetAddress() *URI {
if len(c.addresses) == 0 {
return nil
}
// Return the transport, e.g., http from http+protobuf
uri := c.addresses[c.nextIndex%len(c.addresses)]
c.nextIndex = (c.nextIndex + 1) % len(c.addresses)
return uri
}

// GetAddresses returns all addresses in this cluster
func (c *Cluster) GetAddresses() []URI {
arr := make([]URI, 0, len(c.addresses))
for _, u := range c.addresses {
arr = append(arr, *u)
}
return arr
}
43 changes: 43 additions & 0 deletions cluster_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pilosa

import "testing"

func TestNewClusterWithAddress(t *testing.T) {
c := NewClusterWithAddress(NewURI())
addresses := c.GetAddresses()
if len(addresses) != 1 || !addresses[0].Equals(NewURI()) {
t.Fail()
}
}

func TestAddAddress(t *testing.T) {
const addr = "http://localhost:3000"
c := NewCluster()
if c.GetAddresses() == nil {
t.Fatalf("GetAddresses should not be nil")
}
uri, err := NewURIFromAddress(addr)
if err != nil {
t.Fatalf("Cannot parse address")
}
target, err := NewURIFromAddress(addr)
if err != nil {
t.Fatalf("Cannot parse address")
}
c.AddAddress(uri)
addresses := c.GetAddresses()
if len(addresses) != 1 || !addresses[0].Equals(target) {
t.Fail()
}
}

func TestGetAddress(t *testing.T) {
c := NewCluster()
if c.GetAddress() != nil {
t.Fatalf("GetAddress with empty cluster should return nil")
}
c = NewClusterWithAddress(NewURI())
if !c.GetAddress().Equals(NewURI()) {
t.Fatalf("GetAddres should return a value if there are addresses in the cluster")
}
}
8 changes: 8 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package: github.com/pilosa/gopilosa
import:
- package: github.com/golang/protobuf
subpackages:
- proto
132 changes: 0 additions & 132 deletions http.go

This file was deleted.

Loading

0 comments on commit 2679dca

Please sign in to comment.