When trying to call a method of a Node object returned by a call to neoism.CypherQuery
, I keep getting "invalid memory address or nil pointer dereference" panics. The query returns something (accessing the Data
property of the Node
works), but calling any method leads to a panic. The methods have the receiver *Node
, not Node
, but AFAIK that should work nevertheless? Anyway, I have already tried getting a pointer to the object and calling the method on that, but that didn't work either. I'm really stuck here...
Example code to reproduce the problem (needs neoism and go-uuid packages and a Neo4J DB running on localhost):
package main
import (
"code.google.com/p/go-uuid/uuid"
"fmt"
"github.com/jmcvetta/neoism"
)
func main() {
neo, _ := neoism.Connect("http://localhost:7474/db/data")
// create a node with a random id
nodeId := uuid.New()
_, err := neo.CreateNode(neoism.Props{"NodeId": nodeId})
if err != nil {
fmt.Println(err)
return
}
fmt.Println("node created, id", nodeId)
// find the node by the id
res := []struct {
Node neoism.Node `json:"nodes"`
}{}
err = neo.Cypher(&neoism.CypherQuery{
Statement: `MATCH (nodes {NodeId:{NodeId}}) RETURN nodes`,
Parameters: neoism.Props{"NodeId": nodeId},
Result: &res,
})
if err != nil {
fmt.Println(err)
return
}
fmt.Println("query executed")
// try to work with the query results
if len(res) > 0 {
// get Data -> works
fmt.Println(res[0].Node.Data)
// call method -> panics
err = res[0].Node.SetProperty("TestProp", "TestValue")
if err != nil {
fmt.Println(err)
return
}
}
}
Here's the relevant part of the stack trace:
goroutine 1 [running]:
github.com/jmcvetta/neoism.(*entity).SetProperty(0x119abc00, 0x5d3a68, 0x8, 0x5d3a88, 0x9, ...)
.../src/github.com/jmcvetta/neoism/entity.go:26 +0x104
main.main()
.../src/nieware/neoprob/neoprob.go:41 +0x4cb