add some debug stuff

This commit is contained in:
Lennard Brinkhaus 2023-05-26 12:19:36 +02:00
parent 8113adba53
commit 7d494d5f7a
Signed by: lennard.brinkhaus
GPG Key ID: 286421EC53998B22
3 changed files with 20 additions and 1 deletions

2
go.sum
View File

@ -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=

10
main.go
View File

@ -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)

View File

@ -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)
}
}