This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
otter-space-sdk/pkg/graph/graph_impl.go
SoXX fc73377d86 chore(post): code & folder restructure
Signed-off-by: SoXX <soxx@fenpa.ws>
2024-05-31 15:08:24 +02:00

43 lines
938 B
Go

package graph
import (
"context"
"git.dragse.it/anthrove/otter-space-sdk/internal/utils"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/config"
)
type graphConnection struct {
driver neo4j.DriverWithContext
graphDebug bool
}
func NewGraphConnection(graphDebug bool) OtterSpace {
return &graphConnection{
driver: nil,
graphDebug: graphDebug,
}
}
func (g *graphConnection) Connect(ctx context.Context, endpoint string, username string, password string) error {
driver, err := neo4j.NewDriverWithContext(endpoint, neo4j.BasicAuth(username, password, ""),
logger(g.graphDebug))
if err != nil {
return err
}
err = driver.VerifyAuthentication(ctx, nil)
if err != nil {
return err
}
g.driver = driver
return nil
}
func logger(graphDebug bool) func(config *config.Config) {
return func(config *config.Config) {
config.Log = utils.NewGraphLogger(graphDebug)
}
}