File: data_unsortedkv.go

package info (click to toggle)
golang-github-evilsocket-islazy 1.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 292 kB
  • sloc: javascript: 8; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 661 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main

import (
	"fmt"

	"github.com/evilsocket/islazy/data"
)

func main() {
	// create a new unsorted key value store on /tmp/ukv.dat
	// it'll be flushed on each modification
	kv, err := data.NewDiskUnsortedKV("/tmp/ukv.dat")
	if err != nil {
		panic(err)
	}
	// set a few values
	kv.Set("foo", "bar")
	kv.Set("moo", "boo")
	kv.Set("burn", "the witches")

	// load it
	kv2, err := data.NewDiskUnsortedKVReader("/tmp/ukv.dat")
	if err != nil {
		panic(err)
	}
	// print each object (they'll be in a different order each time)
	kv2.Each(func(key, value string) bool {
		fmt.Printf("%s => %s\n", key, value)
		// don't stop the loop
		return false
	})
}