From 7d494d5f7ab4edba04cef1a159413b6663c185a4 Mon Sep 17 00:00:00 2001 From: Lennard Brinkhaus Date: Fri, 26 May 2023 12:19:36 +0200 Subject: [PATCH] add some debug stuff --- go.sum | 2 ++ main.go | 10 ++++++++++ neo4jAPI/connection.go | 9 ++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/go.sum b/go.sum index 7312b1e..cb4c7a3 100644 --- a/go.sum +++ b/go.sum @@ -7,9 +7,11 @@ github.com/neo4j/neo4j-go-driver/v5 v5.8.1 h1:IysKg6KJIUgyItmnHRRrt2N8srbd6znMsl github.com/neo4j/neo4j-go-driver/v5 v5.8.1/go.mod h1:Vff8OwT7QpLm7L2yYr85XNWe9Rbqlbeb9asNXJTHO4k= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= diff --git a/main.go b/main.go index 20fb1d9..afd552b 100644 --- a/main.go +++ b/main.go @@ -19,12 +19,22 @@ func main() { log.Println(err) } + log.Println("Setup Neo4J Connection") // Connect to Neo4j DB driver, err := neo4jAPI.NewConnection(config.Neo4jURL, config.Neo4jUsername, config.Neo4jPassword) if err != nil { log.Fatal(err) } + err = driver.VerifyAuthentication(context.Background(), nil) + + if err != nil { + log.Println("Cannot connect and authenticate to NEO4J DB") + log.Fatal(err) + } + + log.Println("Connection successful") + ctx := context.Background() defer func(driver neo4j.DriverWithContext, ctx context.Context) { err := driver.Close(ctx) diff --git a/neo4jAPI/connection.go b/neo4jAPI/connection.go index 872da04..11bc9aa 100644 --- a/neo4jAPI/connection.go +++ b/neo4jAPI/connection.go @@ -6,10 +6,17 @@ import ( ) func NewConnection(uri string, username string, password string) (neo4j.DriverWithContext, error) { - driver, err := neo4j.NewDriverWithContext(uri, neo4j.BasicAuth(username, password, "")) + driver, err := neo4j.NewDriverWithContext(uri, neo4j.BasicAuth(username, password, ""), + useConsoleLogger(neo4j.DEBUG)) if err != nil { return nil, fmt.Errorf("failed to create Neo4j driver: %v", err) } return driver, nil } + +func useConsoleLogger(level neo4j.LogLevel) func(config *neo4j.Config) { + return func(config *neo4j.Config) { + config.Log = neo4j.ConsoleLogger(level) + } +}