neo4j

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

README

db/neo4j

Import path: github.com/InsideGallery/core/db/neo4j

Package neo4j provides Neo4j driver configuration and a core-owned graph client boundary. New code should use Graph or GraphClient so application-facing code does not expose Neo4j SDK driver types.

Main APIs

  • Options configures host, credentials, realm, Kerberos ticket, bearer token, and auth type.
  • NewGraphClient(ctx, options) creates a GraphClient and verifies connectivity before returning.
  • Graph is the core-owned interface for connectivity verification and close operations.
  • Result reports graph operation status.
  • ConnectionConfig and GetConnectionConfigFromEnv() read NEO4J_* environment variables.
  • ConnectionConfig.TokenManager(m) returns the supplied token manager or creates one from config.
  • TypeBasicAuth, TypeKerberosAuth, and TypeBearerAuth select supported auth modes. Other values use Neo4j no-auth.
  • Client and GetConnection are legacy SDK-shaped APIs.

Usage

package example

import (
	"context"

	"github.com/InsideGallery/core/db/neo4j"
)

func verify(ctx context.Context) (err error) {
	client, err := neo4j.NewGraphClient(ctx, neo4j.Options{
		Host:     "neo4j://127.0.0.1:7687",
		Login:    "neo4j",
		Password: "secret",
		TypeAuth: neo4j.TypeBasicAuth,
	})
	if err != nil {
		return err
	}
	defer func() {
		if closeErr := client.Close(ctx); err == nil {
			err = closeErr
		}
	}()

	_, err = client.Verify(ctx)
	return err
}

Configuration And Operations

Environment variables include NEO4J_LOGIN, NEO4J_PASSWORD, NEO4J_REALM, NEO4J_TICKET, NEO4J_TOKEN, NEO4J_HOST, and NEO4J_AUTH. NewGraphClient closes the driver if verification fails. Close the graph client during shutdown.

Documentation

Overview

Package neo4j provides Neo4j graph client helpers.

New code should use the core-owned graph boundary:

import "github.com/InsideGallery/core/db/neo4j"

client, err := neo4j.NewGraphClient(ctx, neo4j.Options{Host: "neo4j://127.0.0.1:7687"})

Prefer Graph, Options, and Result in application-facing code so the Neo4j SDK driver type stays inside this adapter package.

Compatibility: Client and GetConnection remain available for existing SDK-shaped callers. Prefer NewGraphClient for new integrations.

Index

Constants

View Source
const (
	TypeBasicAuth    = "BasicAuth"
	TypeKerberosAuth = "KerberosAuth"
	TypeBearerAuth   = "BearerAuth"
)
View Source
const EnvPrefix = "NEO4J"

EnvPrefix environment prefix for gremlin config

Variables

This section is empty.

Functions

This section is empty.

Types

type Client deprecated

type Client struct {
	neo4j.DriverWithContext
	// contains filtered or unexported fields
}

Client is the legacy Neo4j SDK-shaped client.

Deprecated: use GraphClient and core-owned option/result types for new code.

func GetConnection deprecated

func GetConnection(
	ctx context.Context,
	cfg *ConnectionConfig,
) (*Client, error)

GetConnection creates the legacy Neo4j SDK-shaped client.

Deprecated: use NewGraphClient for new code.

func (*Client) Close

func (c *Client) Close() error

type ConnectionConfig

type ConnectionConfig struct {
	Login    string `env:"_LOGIN" envDefault:"neo4j"`
	Password string `env:"_PASSWORD" envDefault:""`
	Realm    string `env:"_REALM" envDefault:""`
	Ticket   string `env:"_TICKET" envDefault:""`
	Token    string `env:"_TOKEN" envDefault:""`
	Host     string `env:"_HOST" envDefault:"neo4j://127.0.0.1:8080"`
	TypeAuth string `env:"_AUTH" envDefault:"NoAuth"`
}

ConnectionConfig contains required data for gremlin

func GetConnectionConfigFromEnv

func GetConnectionConfigFromEnv() (*ConnectionConfig, error)

GetConnectionConfigFromEnv return aerospike configs bases on environment variables

func (*ConnectionConfig) TokenManager

func (c *ConnectionConfig) TokenManager(m auth.TokenManager) auth.TokenManager

type Graph added in v1.1.0

type Graph interface {
	Verify(ctx context.Context) (Result, error)
	Close(ctx context.Context) error
}

Graph is the core-owned Neo4j contract for new consumers.

type GraphClient added in v1.1.0

type GraphClient struct {
	// contains filtered or unexported fields
}

GraphClient wraps the Neo4j driver behind core-owned operation inputs and results.

func NewGraphClient added in v1.1.0

func NewGraphClient(ctx context.Context, options Options) (*GraphClient, error)

NewGraphClient creates a Neo4j graph client from core-owned options.

func (*GraphClient) Close added in v1.1.0

func (c *GraphClient) Close(ctx context.Context) error

Close closes the Neo4j graph client.

func (*GraphClient) Verify added in v1.1.0

func (c *GraphClient) Verify(ctx context.Context) (Result, error)

Verify verifies Neo4j connectivity.

type Options added in v1.1.0

type Options struct {
	Host     string
	Login    string
	Password string
	Realm    string
	Ticket   string
	Token    string
	TypeAuth string
}

Options is the core-owned input for creating a Neo4j graph client.

type Result added in v1.1.0

type Result struct {
	Connected bool
}

Result is the core-owned result for Neo4j graph client operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL