leveldb-go示例,文档

LevelDB-Go 是Go语言中LevelDB的端口。
LevelDB-Go通常被称为Go应用程序的本机替代品。
网站没有示例,也没有文档。</ p>

< p>我应该通过阅读源代码来学习它吗?\没有其他带有示例和文档的网站吗?</ p>

库是否支持并发?</ p>
</ div>

展开原文

原文

LevelDB-Go is port of LevelDB in Go language. LevelDB-Go often referred as native alternative for Go apps. Website has no examples and no documentation.

Should I learn it by reading source code? or there is another website with examples and docs?

Does library support concurrency?

3个回答

I played around a little with leveldb Here is what I got so far. This should get you started.

package main

import (
    "code.google.com/p/leveldb-go/leveldb/db"
    "code.google.com/p/leveldb-go/leveldb/table"
    "fmt"
    "runtime"
)

type kv struct {
    K []byte
    V []byte
}

type kvs struct {
    items map[int]kv
}

func (p *kv) PutKV(k []byte, v []byte) {
    p.K = k
    p.V = v
}

func (items *kvs) PutKVs() {
    fmt.Println(items)
}

func (p *kv) GetKV() (key []byte, value []byte) {
    key = p.K
    value = p.V
    return
}

func Check(e error) {
    if e != nil {
        _, file, line, _ := runtime.Caller(1)
    }
}

func p(r []byte, e error) {
    if e != nil {
        return e
    }
    println(string(r))
}

const (
    DBFILE = "/tmp/leveldb2.db"
)

var DBFS = db.DefaultFileSystem

func main() {
    Connection, e := DBFS.Create(DBFILE)
    Check(e)
    w := table.NewWriter(Connection, nil)
    defer w.Close()

    e = w.Set([]byte("1"), []byte("red"), nil)
    Check(e)
    e = w.Set([]byte("2"), []byte("yellow"), nil)
    Check(e)
    e = w.Set([]byte("3"), []byte("blue"), nil)
    Check(e)
    e = w.Close()
    Check(e)
    w = nil

    count()

    fmt.Println("Printing # KV")
    itemsKV := readByte()
    fmt.Println(itemsKV[0])
    fmt.Println(itemsKV[1])
    fmt.Println(itemsKV[2])
    println("Done Printing # KV")

    Connection, e = DBFS.Create(DBFILE)
    Check(e)
    w = table.NewWriter(Connection, nil)
    defer w.Close()
    e = w.Set([]byte("4"), []byte("green"), nil)
    Check(e)
    e = w.Set([]byte("5"), []byte("white"), nil)
    Check(e)
    e = w.Set([]byte("6"), []byte("black"), nil)
    Check(e)
    e = w.Close()
    Check(e)
}

func count() {
    Connection, e := DBFS.Open(DBFILE)
    Check(e)
    b := []byte("0")
    r := table.NewReader(Connection, nil)

    println("

###### Counting ###### ")

    iter, n := r.Find(b, nil), 0
    for iter.Next() {
        n++
        println("Count # ", n)
    }

    e = r.Close()
    Check(e)
    println("#####Total: ", n)
}

func read() map[int64]string {
    Connection, e := DBFS.Open(DBFILE)
    Check(e)
    b := []byte("0")
    r := table.NewReader(Connection, nil)

    items := map[int64]string{}
    iter, _ := r.Find(b, nil), 0
    for iter.Next() {
        k := iter.Key()
        v := iter.Value()
        items[int64(k[0])] = string(v)
    }

    e = r.Close()
    Check(e)
    return items
}

func readByte() map[int]kv {
    Connection, e := DBFS.Open(DBFILE)
    Check(e)
    c := 0
    b := []byte("0")
    r := table.NewReader(Connection, nil)

    //items := map[int64]kv{}
    item := new(kv)
    items := map[int]kv{}
    iter, _ := r.Find(b, nil), 0
    for iter.Next() {
        k := iter.Key()
        v := iter.Value()
        item.PutKV(k, v)
        items[c] = *item
        c++
    }

    e = r.Close()
    Check(e)
    return items
}

func findOne(k []byte) []byte {
    Connection, e := DBFS.Open(DBFILE)
    Check(e)
    b := []byte("0")
    r := table.NewReader(Connection, nil)

    iter, _ := r.Find(b, nil), 0
    k = iter.Key()
    v := iter.Value()

    e = r.Close()
    Check(e)
    return v
}
dongwei8440
dongwei8440 为什么为什么要在每个功能上继续打开文件? 那不应该作为指针传递吗? 连接,e:= DBFS.Open(DBFILE)
6 年多之前 回复



如果我此时从邮件列表中回想,LevelDB-Go尚不完整。 这可能解释了缺少文档和示例的原因。 您可以使用项目问题跟踪工具索取文档和/或ping作者,以查看其是否准备就绪。</ p>
</ div>

展开原文

原文

If I recall from the mailing lists at this time LevelDB-Go is not complete. That likely explains the lack of documentation and examples. You could use the projects issue tracker to request documentation and/or ping the authors to see if it's ready for use or not.



LevelDB-Go尚未完成,但是有可用的leveldb包装,名为 levigo
您可以查阅其 文档。</ p>
</ div>

展开原文

原文

LevelDB-Go is unfinished, but there is wrapper for leveldb available, named levigo. You can consult its documentation too.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐