Example #1
0
func newFromConfig(ld blobserver.Loader, config jsonconfig.Obj) (blobserver.Storage, error) {
	blobPrefix := config.RequiredString("blobSource")
	mongoConf, err := mongo.ConfigFromJSON(config)
	if err != nil {
		return nil, err
	}
	kv, err := mongo.NewKeyValue(mongoConf)
	if err != nil {
		return nil, err
	}

	ix, err := index.New(kv)
	if err != nil {
		return nil, err
	}

	sto, err := ld.GetStorage(blobPrefix)
	if err != nil {
		return nil, err
	}
	ix.BlobSource = sto

	// Good enough, for now:
	ix.KeyFetcher = ix.BlobSource

	return ix, err
}
Example #2
0
func newSorted(t *testing.T) (kv sorted.KeyValue, cleanup func()) {
	skipOrFailIfNoMongo(t)

	// connect without credentials and wipe the database
	cfg := mongo.Config{
		Server:   "localhost",
		Database: "camlitest",
	}
	var err error
	kv, err = mongo.NewKeyValue(cfg)
	if err != nil {
		t.Fatal(err)
	}
	wiper, ok := kv.(sorted.Wiper)
	if !ok {
		panic("mongo KeyValue not a Wiper")
	}
	err = wiper.Wipe()
	if err != nil {
		t.Fatal(err)
	}
	return kv, func() {
		kv.Close()
	}
}