-
Notifications
You must be signed in to change notification settings - Fork 0
/
neo4j.go
47 lines (36 loc) · 828 Bytes
/
neo4j.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package nksh
import (
"fmt"
"os"
"github.com/denkhaus/nksh/shared"
"github.com/juju/errors"
"github.com/neo4j/neo4j-go-driver/neo4j"
)
func ConnectNeo4j(host string) error {
log.Info("connect neo4j")
user := os.Getenv("NEO4J_USERNAME")
if user == "" {
return errors.New("Neo4j username undefined")
}
password := os.Getenv("NEO4J_PASSWORD")
if password == "" {
return errors.New("Neo4j password undefined")
}
driver, err := neo4j.NewDriver(fmt.Sprintf("bolt://%s:7687", host),
neo4j.BasicAuth(user, password, ""),
)
if err != nil {
return errors.Annotate(err, "NewDriver")
}
shared.Neo4jDriver = driver
return nil
}
func Neo4jDriver() neo4j.Driver {
return shared.Neo4jDriver
}
func CloseNeo4j() {
if shared.Neo4jDriver != nil {
shared.Neo4jDriver.Close()
shared.Neo4jDriver = nil
}
}