Maps on the file system
If you have a big map that's forcing you to run your Go program on an expensive instance with lots of RAM, filemap may be for you.
package main
import (
"bytes"
"io/ioutil"
"log"
"github.com/ijt/filemap"
)
func main() {
d, err := ioutil.TempDir("", "")
if err != nil {
log.Fatal(err)
}
m := filemap.New(d)
k := "hello"
v := []byte("world")
if err := m.Set(k, v); err != nil {
log.Fatal(err)
}
if !m.Has(k) {
log.Fatal("map does not contain key after it was set")
}
v2, err := m.Get(k)
if err != nil {
log.Fatal(err)
}
if !bytes.Equal(v2, v) {
log.Fatalf("Get returned %s, want %s", v2, v)
}
}
make test
make bench