Ejemplo n.º 1
0
func (ls *LevelDBStore) QueryStringIP(ip string) ([]string, error) {
	var docs []string
	key, err := ipset.IPStringToByteString(ip)
	if err != nil {
		return nil, err
	}
	v, err := ls.db.Get([]byte(key), nil)
	if err == leveldb.ErrNotFound {
		return docs, nil
	}
	codec := ls.codecFactory()
	codec.FromBytes(v)
	bs := codec.ToBitset()
	return ls.bitsetToDocs(bs)
}
Ejemplo n.º 2
0
func (bs *BoltStore) QueryString(ip string) {
	key, err := ipset.IPStringToByteString(ip)
	if err != nil {
		fmt.Println(err)
		return
	}
	err = bs.db.View(func(tx *bolt.Tx) error {
		b := tx.Bucket([]byte("docs"))
		ipBucket := tx.Bucket([]byte("ips"))
		v := ipBucket.Get([]byte(key))
		if v == nil {
			fmt.Printf("%s does not exist\n", ip)
			return nil
		}
		bs := bitset.New(8)
		bs.ReadFrom(bytes.NewBuffer(v))
		for i, e := bs.NextSet(0); e; i, e = bs.NextSet(i + 1) {
			fmt.Printf("Match in document %d %s\n", i, DocumentIDToName(b, uint64(i)))
		}
		return nil
	})
	return
}