从neo4j-go-driver连接中获取数据时出现错误。

huangapple go评论141阅读模式
英文:

Error while fetch data from db with neo4j-go-driver connection

问题

	if err != nil {
		logger.Log.Printf("DEBUG:1 GetStockComments : %s", err.Error())
		return []Comment{}, err
	}
	var records []Comment

	comment := Comment{}
	for result.Next() {
		record := result.Record()
		if value, ok := record.Get("c"); ok {
			node := value.(neo4j.Node)
			props := node.Props()
			err := mapstructure.Decode(props, &comment)
			if err != nil {
				logger.Log.Printf("DEBUG:2 GetStockComments : %s", err.Error())
				return []Comment{}, err
			}
			records = append(records, comment)
		}
	}

session.Runresult.Next()的某些时候出现了错误。在Postman中没有显示错误,但是当我尝试使用代码按顺序运行API时,就会出现这个错误。错误信息如下:

runtime error: invalid memory address or nil pointer dereference
goroutine 122 [running]:
net/http.(*conn).serve.func1(0xc0002ba500)
        /usr/lib/go-1.13/src/net/http/server.go:1767 +0x139
panic(0x964400, 0xf64c70)
        /usr/lib/go-1.13/src/runtime/panic.go:679 +0x1b2
github.com/neo4j/neo4j-go-driver/neo4j.(*result).doFetch(0xc0001f7b00, 0x0)
        /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/result.go:73 +0x32
github.com/neo4j/neo4j-go-driver/neo4j.(*result).fetchAll(0xc0001f7b00)
        /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/result.go:134 +0x31
github.com/neo4j/neo4j-go-driver/neo4j.(*session).consumeCurrent(0xc00020e000, 0x1, 0x0)
        /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/session.go:433 +0x34
github.com/neo4j/neo4j-go-driver/neo4j.(*session).Run(0xc00020e000, 0xa1ec6a, 0x8b, 0xc000703860, 0x0, 0x0, 0x0, 0xc0002d6a80, 0x7f8ecca62008, 0x0, ...)
        /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/session.go:450 +0x4a
英文:
	if err != nil {
		logger.Log.Printf("DEBUG:1 GetStockComments : s%", err.Error())
		return []Comment{}, err
	}
	var records []Comment

	comment := Comment{}
	for result.Next() {
		record := result.Record()
		if value, ok := record.Get("c"); ok {
			node := value.(neo4j.Node)
			props := node.Props()
			err := mapstructure.Decode(props, &comment)
			if err != nil {
				logger.Log.Printf("DEBUG:2 GetStockComments : s%", err.Error())
				return []Comment{}, err
			}
			records = append(records, comment)
		}
	}

Some time on Session.run, result.Next()
Error not shown on the postman, when I try to run APIs in sequence using code then it will happen

runtime error: invalid memory address or nil pointer dereference
goroutine 122 [running]:
net/http.(*conn).serve.func1(0xc0002ba500)
        /usr/lib/go-1.13/src/net/http/server.go:1767 +0x139
panic(0x964400, 0xf64c70)
        /usr/lib/go-1.13/src/runtime/panic.go:679 +0x1b2
github.com/neo4j/neo4j-go-driver/neo4j.(*result).doFetch(0xc0001f7b00, 0x0)
        /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/result.go:73 +0x32
github.com/neo4j/neo4j-go-driver/neo4j.(*result).fetchAll(0xc0001f7b00)
        /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/result.go:134 +0x31
github.com/neo4j/neo4j-go-driver/neo4j.(*session).consumeCurrent(0xc00020e000, 0x1, 0x0)
        /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/session.go:433 +0x34
github.com/neo4j/neo4j-go-driver/neo4j.(*session).Run(0xc00020e000, 0xa1ec6a, 0x8b, 0xc000703860, 0x0, 0x0, 0x0, 0xc0002d6a80, 0x7f8ecca62008, 0x0, ...)
        /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/session.go:450 +0x4a

答案1

得分: 1

我已经解决了这个问题,我只是在项目启动时开始了数据库会话,但是我需要在每次查询运行时都开始和关闭。这解决了我的问题,谢谢大家...

英文:

I have solved this issue, I just start DB session on project start, but I need to start and close on every query run. This solved my problem, thanks all...

huangapple
  • 本文由 发表于 2021年11月24日 16:24:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/70092763.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定