Пример #1
0
func testFile() {
	db, err := blobdb.New(dbpath)
	if err != nil {
		fmt.Println(err)
		return
	}

	meta := blob.NewMeta()
	blobs, err := meta.LoadFromPath(testfilepath)
	if err != nil {
		fmt.Println(err)
		return
	}

	err = db.Put(blobs...)
	if err != nil {
		fmt.Println(err)
		return
	}

	m, _ := blob.Marshal(meta)
	err = db.Put(m)
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, b := range blobs {
		fmt.Println(b)
	}
}
Пример #2
0
func configServ(addr, dbPath string) *Server {
	db, _ := blobdb.New(dbPath)
	tInd := timeindex.New()
	oInd := objindex.New()
	for b := range db.Walk() {
		tInd.Notify(b)
		oInd.Notify(b)
	}
	sort.Sort(tInd)
	oInd.Sort()

	serv := defaultHttpServer()
	serv.Addr = addr
	bs := &Server{Db: db, Serv: serv}
	bs.AddIndex("time", tInd)
	bs.AddIndex("object", oInd)
	return bs
}
Пример #3
0
func (bs *Server) prepareListen() {
	if bs.inds == nil {
		bs.inds = make(map[string]index.Index, 0)
	}

	if bs.Db == nil {
		bs.Db, _ = blobdb.New(DefaultDb)
	}

	if bs.Serv == nil {
		bs.Serv = defaultHttpServer()
	}

	http.Handle("/", &defHandler{})
	http.Handle("/ref/", auth.Handler{&getHandler{bs: bs}})
	http.Handle("/put/", auth.Handler{&putHandler{bs: bs}})
	http.Handle("/index/", auth.Handler{&indexHandler{bs: bs}})
}
Пример #4
0
func testRaw() {
	db, err := blobdb.New(dbpath)
	if err != nil {
		fmt.Println(err)
		return
	}

	b := blob.NewRaw([]byte("hello monkey man"))
	err = db.Put(b)
	if err != nil {
		fmt.Println(err)
		return
	}

	b2, err := db.Get(b.Ref())
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(b)
	fmt.Println(b2)
}
Пример #5
0
func testDir() {
	db, _ := blobdb.New(dbpath)

	metas, blobs, err := blob.DirBlobsAndMeta(testdirpath)
	if err != nil {
		fmt.Println(err)
		return
	}

	metablobs := make([]*blob.Blob, 0)
	for _, meta := range metas {
		obj := blob.NewObject()
		meta.RcasObjectRef = obj.Ref()
		m, _ := blob.Marshal(meta)
		metablobs = append(metablobs, m, obj)
	}

	err = db.Put(metablobs...)
	if err != nil {
		fmt.Println(err)
		return
	}

	err = db.Put(blobs...)
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, b := range metablobs {
		fmt.Println(b)
	}
	for _, b := range blobs {
		fmt.Println(b)
	}
}