Created
July 10, 2019 14:47
-
-
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
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
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