Created
August 21, 2013 04:39
-
-
Save wathiede/6290382 to your computer and use it in GitHub Desktop.
Enumerating blobs in camlistore
This file contains hidden or 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
// ex will enumerate over all blobs, printing out the schema blobs found. | |
// | |
// To connect to the server setup in your | |
// ~/.config/camlistore/client-config.json or equivalent: | |
// | |
// go run ex.go | |
// | |
// or specify the server address to connect to: | |
// | |
// go run ex.go cam.example.com:3179 | |
package main | |
import ( | |
"flag" | |
"log" | |
"camlistore.org/pkg/blob" | |
"camlistore.org/pkg/client" | |
) | |
func main() { | |
flag.Parse() | |
var c *client.Client | |
host := flag.Arg(0) | |
if host != "" { | |
c = client.New(host) | |
err := c.SetupAuth() | |
if err != nil { | |
log.Fatal(err) | |
} | |
} else { | |
c = client.NewOrFail() | |
} | |
dest := make(chan blob.SizedRef) | |
opts := client.EnumerateOpts{Limit: 0} | |
go func(ch chan blob.SizedRef) { | |
err := c.EnumerateBlobsOpts(ch, opts) | |
if err != nil { | |
log.Fatal(err) | |
} | |
}(dest) | |
for sr := range dest { | |
b, err := c.FetchSchemaBlob(sr.Ref) | |
if err != nil { | |
// Not a schema blob. Probably add to your list of GC candidates. | |
continue | |
} | |
// Do something with the schema, like in processCamliFile, except now | |
// you have a nice data structure instead of traversing nested | |
// map[string]interface{} | |
log.Println("b", b) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment