Skip to content
This repository has been archived by the owner on Nov 23, 2018. It is now read-only.

Commit

Permalink
Fix test/example
Browse files Browse the repository at this point in the history
  • Loading branch information
c2h5oh committed Mar 19, 2018
1 parent 834599a commit 6a37422
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 42 deletions.
35 changes: 14 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/pressly/chainstore"
"github.com/pressly/chainstore/boltstore"
"github.com/pressly/chainstore/lrumgr"
"github.com/pressly/chainstore/metricsmgr"
"github.com/pressly/chainstore/s3store"
"golang.org/x/net/context"
)
Expand All @@ -47,30 +46,31 @@ func main() {
ctx := context.Background()

diskStore := lrumgr.New(500*1024*1024, // 500MB of working data
metricsmgr.New("chainstore.ex.bolt",
boltstore.New("/tmp/store.db", "myBucket"),
),
boltstore.New("/tmp/store.db", "myBucket"),
)

remoteStore := metricsmgr.New("chainstore.ex.s3",
// NOTE: you'll have to supply your own keys in order for this example to work properly
s3store.New(bucketID, accessKey, secretKey),
)
remoteStore := s3store.New(s3store.Config{
S3Bucket: bucketID,
S3AccessKey: accessKey,
S3SecretKey: secretKey,
S3Region: region,
})

dataStore := chainstore.New(diskStore, remoteStore)

// OR.. define inline. Except, I wanted to show store independence & state.
/*
dataStore := chainstore.New(
lrumgr.New(500*1024*1024, // 500MB of working data
metricsmgr.New("chainstore.ex.bolt",
boltstore.New("/tmp/store.db", "myBucket"),
),
boltstore.New("/tmp/store.db", "myBucket"),
),
metricsmgr.New("chainstore.ex.s3",
s3store.New(s3store.Config{
// NOTE: you'll have to supply your own keys in order for this example to work properly
s3store.New("myBucket", "access-key", "secret-key"),
),
S3Bucket: bucketID,
S3AccessKey: accessKey,
S3SecretKey: secretKey,
S3Region: region,
})
)
*/

Expand All @@ -81,13 +81,6 @@ func main() {
log.Fatalf("Open: %q", err)
}

// Since we've used the metricsManager above (metricsmgr), any calls to the boltstore
// and s3store will be measured. Next is to send metrics to librato, graphite, influxdb,
// whatever.. via github.com/goware/go-metrics
// go librato.Librato(metrics.DefaultRegistry, 10e9, ...)

//--

// Save the object in the chain. It will be Put() synchronously into diskStore,
// the boltdb engine, and then immediately dispatch background Put()'s to the
// other stores down the chain, in this case S3.
Expand Down
41 changes: 20 additions & 21 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/pressly/chainstore"
"github.com/pressly/chainstore/boltstore"
"github.com/pressly/chainstore/lrumgr"
"github.com/pressly/chainstore/metricsmgr"
"github.com/pressly/chainstore/s3store"
"golang.org/x/net/context"
)
Expand All @@ -18,42 +17,49 @@ var (
bucketID string
accessKey string
secretKey string
region string
)

func init() {
bucketID = os.Getenv("S3_BUCKET")
accessKey = os.Getenv("S3_ACCESS_KEY")
secretKey = os.Getenv("S3_SECRET_KEY")
region = os.Getenv("S3_REGION")

if region == "" {
region = "us-east-1"
}
}

func main() {
ctx := context.Background()

diskStore := lrumgr.New(500*1024*1024, // 500MB of working data
metricsmgr.New("chainstore.ex.bolt",
boltstore.New("/tmp/store.db", "myBucket"),
),
boltstore.New("/tmp/store.db", "myBucket"),
)

remoteStore := metricsmgr.New("chainstore.ex.s3",
// NOTE: you'll have to supply your own keys in order for this example to work properly
s3store.New(bucketID, accessKey, secretKey),
)
remoteStore := s3store.New(s3store.Config{
S3Bucket: bucketID,
S3AccessKey: accessKey,
S3SecretKey: secretKey,
S3Region: region,
})

dataStore := chainstore.New(diskStore, remoteStore)

// OR.. define inline. Except, I wanted to show store independence & state.
/*
dataStore := chainstore.New(
lrumgr.New(500*1024*1024, // 500MB of working data
metricsmgr.New("chainstore.ex.bolt",
boltstore.New("/tmp/store.db", "myBucket"),
),
boltstore.New("/tmp/store.db", "myBucket"),
),
metricsmgr.New("chainstore.ex.s3",
s3store.New(s3store.Config{
// NOTE: you'll have to supply your own keys in order for this example to work properly
s3store.New("myBucket", "access-key", "secret-key"),
),
S3Bucket: bucketID,
S3AccessKey: accessKey,
S3SecretKey: secretKey,
S3Region: region,
})
)
*/

Expand All @@ -64,13 +70,6 @@ func main() {
log.Fatalf("Open: %q", err)
}

// Since we've used the metricsManager above (metricsmgr), any calls to the boltstore
// and s3store will be measured. Next is to send metrics to librato, graphite, influxdb,
// whatever.. via github.com/goware/go-metrics
// go librato.Librato(metrics.DefaultRegistry, 10e9, ...)

//--

// Save the object in the chain. It will be Put() synchronously into diskStore,
// the boltdb engine, and then immediately dispatch background Put()'s to the
// other stores down the chain, in this case S3.
Expand Down

0 comments on commit 6a37422

Please sign in to comment.