douyi8408 2016-03-18 07:02 采纳率: 0%
浏览 35

使用go(cayley)创建新的四边形商店?

I'm new to go and I'm trying to create a Quad store using cayley/graph library(NewQuadStore()). I'm trying to do it on testdata.nq file which is a sample data that comes with cayley. Here is my code:

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()))
}
}

It compiles with no error but generates a panic when I run it. It looks like this :-

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

I tried to look inside the quadstore.go to look for the problem but I couldn't figure it out and I can't find anything on godoc as well. Please Help. Thank You!

  • 写回答

1条回答 默认 最新

  • dongzhao4036 2016-03-18 11:54
    关注
    var register graph.QuadStoreRegistration
    

    This creates a struct with zero values. register.NewFunc is nil. graph.NewQuadStore tries to call it.

    You have to initialize register with some kind of NewFunc, e.g. https://github.com/google/cayley/blob/master/graph/mongo/quadstore.go#L37

    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了