2

我是新手,我正在尝试使用 cayley/图形库(NewQuadStore())创建一个 Quad 商店。我正在尝试在 testdata.nq 文件上执行此操作,该文件是 cayley 附带的示例数据。这是我的代码:

package main

import (
  "fmt"
  "github.com/google/cayley/graph"
  "log"
)

func main() {

var register graph.QuadStoreRegistration
graph.RegisterQuadStore("testdata", register)

store, err := graph.NewQuadStore("testdata", "data/testdata.nq", nil)
if err != nil {
    log.Fatalln(err)
}
defer store.Close()
store.Type()

iterator := store.NodesAllIterator()
for iterator.NextPath() {
    fmt.Println(store.NameOf(iterator.Result()))
}
}

它编译没有错误,但当我运行它时会产生恐慌。它看起来像这样:-

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x47045e]

goroutine 1 [running]:
panic(0x5dbfa0, 0xc82000a120)
/usr/local/go/src/runtime/panic.go:464 +0x3e6
github.com/google/cayley/graph.NewQuadStore(0x625c60, 0x8, 0x642500,   0x10, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/himanshi/dev/go/src/github.com/google/cayley/graph/quadstore.go:179 +0x23e
main.main()
/home/himanshi/dev/go/src/cayley/main.go:14 +0xcd

我试图在 quadstore.go 内部寻找问题,但我无法弄清楚,我在 godoc 上也找不到任何东西。请帮忙。谢谢你!

4

1 回答 1

0
var register graph.QuadStoreRegistration

这将创建一个具有零值的结构。register.NewFunc是零。graph.NewQuadStore试图调用它。

您必须register使用某种初始化NewFunc,例如https://github.com/google/cayley/blob/master/graph/mongo/quadstore.go#L37

于 2016-03-18T11:54:41.010 回答