Created
July 27, 2015 19:21
-
-
Save indraniel/4c6e64df9fa62c111721 to your computer and use it in GitHub Desktop.
A simple example of using LevelDB in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/syndtr/goleveldb/leveldb" | |
"log" | |
) | |
func main() { | |
db, err := leveldb.OpenFile("/tmp/foo.db", nil) | |
if err != nil { | |
log.Fatal("Yikes!") | |
} | |
defer db.Close() | |
// err = db.Put([]byte("fizz"), []byte("buzz"), nil) | |
// err = db.Put([]byte("fizz2"), []byte("buzz2"), nil) | |
// err = db.Put([]byte("fizz3"), []byte("buzz3"), nil) | |
iter := db.NewIterator(nil, nil) | |
for iter.Next() { | |
key := iter.Key() | |
value := iter.Value() | |
fmt.Printf("key: %s | value: %s\n", key, value) | |
} | |
fmt.Println("\n") | |
for ok := iter.Seek([]byte("fizz2")); ok; ok = iter.Next() { | |
key := iter.Key() | |
value := iter.Value() | |
fmt.Printf("key: %s | value: %s\n", key, value) | |
} | |
fmt.Println("\n") | |
for ok := iter.First(); ok; ok = iter.Next() { | |
key := iter.Key() | |
value := iter.Value() | |
fmt.Printf("key: %s | value: %s\n", key, value) | |
} | |
iter.Release() | |
err = iter.Error() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
its doing nothing. not even fmt.print() working. what may be the error ?