This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
4,588 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.