Skip to content

Instantly share code, notes, and snippets.

@bbengfort
Created July 10, 2019 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbengfort/0930549f03627241c15a3f8e2b27bbbb to your computer and use it in GitHub Desktop.
Save bbengfort/0930549f03627241c15a3f8e2b27bbbb to your computer and use it in GitHub Desktop.
Quick example of getting a stream in the btrdb-go bindings and counting the number of points
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/BTrDB/btrdb"
"github.com/PingThingsIO/smartgridstore/modules/creds"
"github.com/pborman/uuid"
)
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
profile, err := creds.Get("")
check(err)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
db, err := btrdb.ConnectAuth(ctx, profile.BTrDB.APIKey, profile.BTrDB.EndpointsList()...)
check(err)
uu := uuid.Parse("2d7829c4-3de2-522c-9a1b-53021d36e973")
stream := db.StreamFromUUID(uu)
if exists, err := stream.Exists(context.Background()); !exists || err != nil {
log.Fatalf("cannot fetch stream: %s\n", err)
}
npoints, err := stream.Count(context.Background(), 0)
check(err)
fmt.Printf("stream has %d points\n", npoints)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment