I've been working on this problem for a few hours, and I haven't had much luck with the community Golang drivers for Neo4j.
I've attempted to run "movies-go-cq" and "neoism" examples. The movies-go-cq example doesn't work for me, it crashes when localhost:8080 is loaded in the browser.
Cypher queries on my Neo4j database with neoism only return empty/blank data. However, when I run the same query in the Neo4j browser at localhost:7474, the expected data is returned.
Here is the Go code I am running with neoism:
package main
import (
"fmt"
"github.com/jmcvetta/neoism"
)
func main() {
// Reference: https://godoc.org/github.com/jmcvetta/neoism
// Connect to the Neo4j server
db, _ := neoism.Connect("http://localhost:7474/db/data")
// Issue a query
res1 := []struct {
A string `json:"path1"` // `json` tag matches column name in query
B string `json:"path2"`
}{}
cq1 := neoism.CypherQuery{
// Use backticks for long statements - Cypher is whitespace indifferent
Statement: `
MATCH path1 = shortestPath( (plant:Plant {Term: "Vaccinium corymbosum"})-[*..5]-(gene:Gene {Description: "adenylate cyclase activating polypeptide 1"}) )
MATCH path2 = shortestPath( (gene)-[*..5]-(disease:Medical_Heading {Term: "Alzheimer Disease"}) )
RETURN path1, path2
`,
Result: &res1,
}
db.Cypher(&cq1)
r := res1[0]
fmt.Println(r.A, r.B)
}
I am considering writing my own API wrapper in Go that uses Neo4j's HTTP RESTful API if I can't get existing Go drivers to work properly; I am new to Golang, and I would be thankful for any advice for debugging Go code or tips for working with Neo4j in Golang. Thank you for your time.
I know what you are facing right now. Some time before I was facing the same issue. There are 2 possible cases are there:-
1) You should always declare struct variable Capital.
res1 := []struct { CAPITAL_STR1 string `json:"path1"` CAPITAL_STR2 string `json:"path2"` }{}
which you are doing exactly right A and B.
2) You have to paste exact json type (There is mistake)
res1 := []struct { CAPITAL_STR1 string `json:"path1.distance"` CAPITAL_STR2 string `json:"path2.distance"` }{}
For getting exact json format check output json response at your Neo4J in browser. It is available under section code.