Files
knowledge-graph-agent/backend/neo4j/client.go
T

28 lines
474 B
Go
Raw Normal View History

2026-04-12 15:47:48 +08:00
package neo4j
import (
"context"
"fmt"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
2026-04-13 14:36:54 +08:00
"knowledge-graph-backend/config"
2026-04-12 15:47:48 +08:00
)
2026-04-13 14:36:54 +08:00
func DoConnect(cfg config.Neo4jConfig) {
ctx := context.Background()
driver, err := neo4j.NewDriverWithContext(
cfg.URI,
neo4j.BasicAuth(cfg.Username, cfg.Password, ""))
if err != nil {
panic(err)
}
defer driver.Close(ctx)
2026-04-12 15:47:48 +08:00
2026-04-13 14:36:54 +08:00
err = driver.VerifyConnectivity(ctx)
if err != nil {
panic(err)
}
fmt.Println("Connection established.")
2026-04-12 15:47:48 +08:00
}