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

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

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

问题

  1. if err != nil {
  2. logger.Log.Printf("DEBUG:1 GetStockComments : %s", err.Error())
  3. return []Comment{}, err
  4. }
  5. var records []Comment
  6. comment := Comment{}
  7. for result.Next() {
  8. record := result.Record()
  9. if value, ok := record.Get("c"); ok {
  10. node := value.(neo4j.Node)
  11. props := node.Props()
  12. err := mapstructure.Decode(props, &comment)
  13. if err != nil {
  14. logger.Log.Printf("DEBUG:2 GetStockComments : %s", err.Error())
  15. return []Comment{}, err
  16. }
  17. records = append(records, comment)
  18. }
  19. }

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

  1. runtime error: invalid memory address or nil pointer dereference
  2. goroutine 122 [running]:
  3. net/http.(*conn).serve.func1(0xc0002ba500)
  4. /usr/lib/go-1.13/src/net/http/server.go:1767 +0x139
  5. panic(0x964400, 0xf64c70)
  6. /usr/lib/go-1.13/src/runtime/panic.go:679 +0x1b2
  7. github.com/neo4j/neo4j-go-driver/neo4j.(*result).doFetch(0xc0001f7b00, 0x0)
  8. /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/result.go:73 +0x32
  9. github.com/neo4j/neo4j-go-driver/neo4j.(*result).fetchAll(0xc0001f7b00)
  10. /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/result.go:134 +0x31
  11. github.com/neo4j/neo4j-go-driver/neo4j.(*session).consumeCurrent(0xc00020e000, 0x1, 0x0)
  12. /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/session.go:433 +0x34
  13. github.com/neo4j/neo4j-go-driver/neo4j.(*session).Run(0xc00020e000, 0xa1ec6a, 0x8b, 0xc000703860, 0x0, 0x0, 0x0, 0xc0002d6a80, 0x7f8ecca62008, 0x0, ...)
  14. /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/session.go:450 +0x4a
英文:
  1. if err != nil {
  2. logger.Log.Printf("DEBUG:1 GetStockComments : s%", err.Error())
  3. return []Comment{}, err
  4. }
  5. var records []Comment
  6. comment := Comment{}
  7. for result.Next() {
  8. record := result.Record()
  9. if value, ok := record.Get("c"); ok {
  10. node := value.(neo4j.Node)
  11. props := node.Props()
  12. err := mapstructure.Decode(props, &comment)
  13. if err != nil {
  14. logger.Log.Printf("DEBUG:2 GetStockComments : s%", err.Error())
  15. return []Comment{}, err
  16. }
  17. records = append(records, comment)
  18. }
  19. }

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

  1. runtime error: invalid memory address or nil pointer dereference
  2. goroutine 122 [running]:
  3. net/http.(*conn).serve.func1(0xc0002ba500)
  4. /usr/lib/go-1.13/src/net/http/server.go:1767 +0x139
  5. panic(0x964400, 0xf64c70)
  6. /usr/lib/go-1.13/src/runtime/panic.go:679 +0x1b2
  7. github.com/neo4j/neo4j-go-driver/neo4j.(*result).doFetch(0xc0001f7b00, 0x0)
  8. /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/result.go:73 +0x32
  9. github.com/neo4j/neo4j-go-driver/neo4j.(*result).fetchAll(0xc0001f7b00)
  10. /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/result.go:134 +0x31
  11. github.com/neo4j/neo4j-go-driver/neo4j.(*session).consumeCurrent(0xc00020e000, 0x1, 0x0)
  12. /root/go/pkg/mod/github.com/neo4j/neo4j-go-driver@v1.8.3/neo4j/session.go:433 +0x34
  13. github.com/neo4j/neo4j-go-driver/neo4j.(*session).Run(0xc00020e000, 0xa1ec6a, 0x8b, 0xc000703860, 0x0, 0x0, 0x0, 0xc0002d6a80, 0x7f8ecca62008, 0x0, ...)
  14. /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:

确定