refactor: 按go modules规范重构
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package neo4j
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
||||
|
||||
"knowledge-graph-backend/internal/config"
|
||||
)
|
||||
|
||||
func NewDriver(cfg config.Neo4jConfig) neo4j.DriverWithContext {
|
||||
ctx := context.Background()
|
||||
driver, err := neo4j.NewDriverWithContext(
|
||||
cfg.URI,
|
||||
neo4j.BasicAuth(cfg.Username, cfg.Password, ""))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = driver.VerifyConnectivity(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return driver
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package neo4j
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"knowledge-graph-backend/internal/config"
|
||||
)
|
||||
|
||||
func TestNewDriver(t *testing.T) {
|
||||
cnf, err := config.Load()
|
||||
if err != nil {
|
||||
t.Errorf("[cnf]: %v", err)
|
||||
}
|
||||
cfg := config.Neo4jConfig{
|
||||
URI: cnf.Neo4j.URI,
|
||||
Username: cnf.Neo4j.Username,
|
||||
Password: cnf.Neo4j.Password,
|
||||
}
|
||||
driver := NewDriver(cfg)
|
||||
defer driver.Close(context.Background())
|
||||
}
|
||||
Reference in New Issue
Block a user