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 }
func testTimeIndex() { ti := timeindex.New() m1 := map[string]string{} m2 := map[string]string{} m3 := map[string]string{} m4 := map[string]string{} m5 := map[string]string{} b1, _ := blob.Marshal(m1) time.Sleep(time.Second * 1) b2, _ := blob.Marshal(m2) time.Sleep(time.Second * 1) b3, _ := blob.Marshal(m3) time.Sleep(time.Second * 1) b4, _ := blob.Marshal(m4) time.Sleep(time.Second * 1) b5, _ := blob.Marshal(m5) ti.Notify(b1, b2, b3, b4, b5) var m map[string]string blob.Unmarshal(b4, &m) t, _ := time.Parse(blob.TimeFormat, m[blob.Timestamp]) i := ti.IndexNear(t.Add(time.Millisecond * -1)) ref := ti.RefAt(i) fmt.Println("retrieved ref:", ref) fmt.Println("all refs:") fmt.Println(b1.Ref()) fmt.Println(b2.Ref()) fmt.Println(b3.Ref()) fmt.Println(b4.Ref()) fmt.Println(b5.Ref()) if ref == b3.Ref() { fmt.Println("success!") } else { fmt.Println("failured") } }