aboutsummaryrefslogtreecommitdiffstats
path: root/examples/storage/aerospike/storage.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-01-29 02:27:16 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2017-01-29 22:36:15 +0100
commitacb1dc80d93f45a055b14903679abca3a6e994f6 (patch)
treea7e29fd677bb5c11df85fca1fcb6d015bc40fa7b /examples/storage/aerospike/storage.go
parent352170d1bf8cc7b32b85d8a2740eb3627e952a6e (diff)
downloadgo-git-acb1dc80d93f45a055b14903679abca3a6e994f6.tar.gz
example: using new constructors
Diffstat (limited to 'examples/storage/aerospike/storage.go')
-rw-r--r--examples/storage/aerospike/storage.go41
1 files changed, 40 insertions, 1 deletions
diff --git a/examples/storage/aerospike/storage.go b/examples/storage/aerospike/storage.go
index 3ce5f5b..712c329 100644
--- a/examples/storage/aerospike/storage.go
+++ b/examples/storage/aerospike/storage.go
@@ -8,6 +8,7 @@ import (
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/format/index"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
driver "github.com/aerospike/aerospike-client-go"
@@ -248,6 +249,44 @@ func (s *Storage) buildConfigKey() (*driver.Key, error) {
return driver.NewKey(s.ns, configSet, fmt.Sprintf("%s|config", s.url))
}
+func (s *Storage) Index() (*index.Index, error) {
+ key, err := s.buildIndexKey()
+ if err != nil {
+ return nil, err
+ }
+
+ rec, err := s.client.Get(nil, key)
+ if err != nil {
+ return nil, err
+ }
+
+ idx := &index.Index{}
+ return idx, json.Unmarshal(rec.Bins["blob"].([]byte), idx)
+}
+
+func (s *Storage) SetIndex(idx *index.Index) error {
+ key, err := s.buildIndexKey()
+ if err != nil {
+ return err
+ }
+
+ json, err := json.Marshal(idx)
+ if err != nil {
+ return err
+ }
+
+ bins := driver.BinMap{
+ urlField: s.url,
+ "blob": json,
+ }
+
+ return s.client.Put(nil, key, bins)
+}
+
+func (s *Storage) buildIndexKey() (*driver.Key, error) {
+ return driver.NewKey(s.ns, configSet, fmt.Sprintf("%s|index", s.url))
+}
+
func (s *Storage) Shallow() ([]plumbing.Hash, error) {
key, err := s.buildShallowKey()
if err != nil {
@@ -283,7 +322,7 @@ func (s *Storage) SetShallow(hash []plumbing.Hash) error {
}
func (s *Storage) buildShallowKey() (*driver.Key, error) {
- return driver.NewKey(s.ns, configSet, fmt.Sprintf("%s|config", s.url))
+ return driver.NewKey(s.ns, configSet, fmt.Sprintf("%s|shallow", s.url))
}
func createIndexes(c *driver.Client, ns string) error {