-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔥 feat: Add support for Neo4j #1562
Merged
+967
−4
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
bba2cc0
neo4j storage driver config.go
the-real-i9 de074c5
New and Get mdthods
the-real-i9 96079e7
(update): other storage interface methods implemented
the-real-i9 32c31af
(test): all tests passed
the-real-i9 c7ef3ee
(update): Config doc update
the-real-i9 3f32afe
(update): Config doc update
the-real-i9 c58fcf2
(fix): repeated condition check
the-real-i9 b49ff3a
(fix): typo fix, changed mysql to arangodb
the-real-i9 fd5f9f7
README update
the-real-i9 8caf6b9
Merge branch 'gofiber:main' into main
the-real-i9 c6792f4
Neo4j README update
the-real-i9 505f371
Neo4j README update
the-real-i9 cb30085
Neo4j README update
the-real-i9 c5fa260
fixes
the-real-i9 9210a55
Merge branch 'gofiber:main' into main
the-real-i9 ddbe487
readme update
the-real-i9 41e11d6
test workflow neo4j
the-real-i9 cf25873
(fixes): neo4j
the-real-i9 511a96b
Merge branch 'gofiber:main' into main
the-real-i9 962c314
(fix): neo4j README
the-real-i9 33d9b48
testcontainer now working fine
the-real-i9 3fc1b8c
Update neo4j/neo4j_test.go
the-real-i9 8657520
(fix): neo4j/neo4j_test.go
the-real-i9 5e5858e
(update): storage.go to include Neo4j package
the-real-i9 4a7a7f0
(update): main README to include Neo4j test image tag
the-real-i9 93c211d
review updates
the-real-i9 7e74ccf
starting separate container for each test is beyond efficient, revert…
the-real-i9 6e08ff8
Merge branch 'gofiber:main' into main
the-real-i9 69a51dc
Update README.md
gaby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
paths: | ||
- 'neo4j/**' | ||
pull_request: | ||
paths: | ||
- 'neo4j/**' | ||
name: "Tests Neo4j" | ||
jobs: | ||
Tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
go-version: | ||
- 1.23.x | ||
steps: | ||
- name: Fetch Repository | ||
uses: actions/checkout@v4 | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '${{ matrix.go-version }}' | ||
- name: Run Test | ||
run: cd ./neo4j && go test ./... -v -race |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
--- | ||
id: neo4j | ||
title: Neo4j | ||
--- | ||
|
||
A Neo4j storage driver using [neo4j/neo4j-go-driver](https://github.com/neo4j/neo4j-go-driver). | ||
|
||
> **Note: Requires latest two release of Golang** | ||
|
||
### Table of Contents | ||
|
||
- [Signatures](#signatures) | ||
- [Installation](#installation) | ||
- [Examples](#examples) | ||
- [Config](#config) | ||
- [Default Config](#default-config) | ||
|
||
### Signatures | ||
|
||
```go | ||
func New(config ...Config) Storage | ||
func (s *Storage) Get(key string) ([]byte, error) | ||
func (s *Storage) Set(key string, val []byte, exp time.Duration) error | ||
func (s *Storage) Delete(key string) error | ||
func (s *Storage) Reset() error | ||
func (s *Storage) Close() error | ||
func (s *Storage) Conn() neo4j.DriverWithContext | ||
``` | ||
|
||
### Installation | ||
|
||
Neo4j is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: | ||
|
||
```bash | ||
go mod init github.com/<user>/<repo> | ||
``` | ||
|
||
And then install the neo4j implementation: | ||
|
||
```bash | ||
go get github.com/gofiber/storage/neo4j | ||
``` | ||
|
||
### Examples | ||
|
||
Import the storage package. | ||
|
||
```go | ||
import neo4jstore "github.com/gofiber/storage/neo4j" | ||
``` | ||
|
||
You can use the following possibilities to create a storage: | ||
|
||
```go | ||
// Initialize default config | ||
store := neo4j.New() | ||
|
||
// Initialize custom config | ||
store := neo4j.New(neo4jstore.Config{ | ||
DB: driver, | ||
Node: "fiber_storage", | ||
Reset: false, | ||
GCInterval: 10 * time.Second, | ||
}) | ||
``` | ||
|
||
### Config | ||
|
||
```go | ||
// Config defines the config for storage. | ||
type Config struct { | ||
// Connection pool | ||
// | ||
// DB neo4j.DriverWithContext object will override connection uri and other connection fields. | ||
// | ||
// Optional. Default is nil. | ||
DB neo4j.DriverWithContext | ||
|
||
// Target Server | ||
// | ||
// Optional. Default is "neo4j://localhost" | ||
URI string | ||
|
||
// Connection authentication | ||
// | ||
// Auth auth.TokenManager will override Username and Password fields | ||
// | ||
// Optional. Default is nil. | ||
Auth auth.TokenManager | ||
|
||
// Connection configurations | ||
// | ||
// Optional. Default is nil | ||
Configurations []func(*config.Config) | ||
|
||
// Server username | ||
// | ||
// Optional. Default is "" | ||
Username string | ||
|
||
// Server password | ||
// | ||
// Optional. Default is "" | ||
Password string | ||
|
||
// Node name | ||
// | ||
// Optional. Default is "fiber_storage" | ||
Node string | ||
|
||
// Reset clears any existing keys in existing Table | ||
// | ||
// Optional. Default is false | ||
Reset bool | ||
|
||
// Time before deleting expired keys | ||
// | ||
// Optional. Default is 10 * time.Second | ||
GCInterval time.Duration | ||
} | ||
``` | ||
|
||
#### A note on Authentication | ||
|
||
If auth is enabled on your server, then authentication must be provided in one of the three ways (the previous overrides the next): | ||
|
||
- Via the connection pool, `neo4j.DriverWithContext`, provided on the `DB` field. | ||
- Via the `Auth` field: it must be an `auth.TokenManager` whose value is any one but `neo4j.NoAuth()`. | ||
- By setting both `Username` and `Password` fields: This will cause this storage driver to use Basic Auth. | ||
|
||
Otherwise, your neo4j driver will panic with authorization error. | ||
|
||
In contrast, if auth is disabled on your server, there's no need to provide any authentication parameter. | ||
|
||
### Default Config | ||
|
||
Used only for optional fields | ||
|
||
```go | ||
var ConfigDefault = Config{ | ||
URI: "neo4j://localhost", | ||
Node: "fiber_storage", | ||
Reset: false, | ||
GCInterval: 10 * time.Second, | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package neo4j | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/neo4j/neo4j-go-driver/v5/neo4j" | ||
"github.com/neo4j/neo4j-go-driver/v5/neo4j/auth" | ||
"github.com/neo4j/neo4j-go-driver/v5/neo4j/config" | ||
) | ||
|
||
type Config struct { | ||
// Connection pool. | ||
// | ||
// DB neo4j.DriverWithContext object will override connection uri and other connection fields. | ||
// | ||
// Optional. Default is nil. | ||
DB neo4j.DriverWithContext | ||
|
||
// Target Server | ||
// | ||
// Optional. Default is "neo4j://localhost" | ||
URI string | ||
|
||
// Connection authentication. | ||
// | ||
// Auth auth.TokenManager will override Username and Password fields. | ||
// | ||
// Optional. Default is nil. | ||
Auth auth.TokenManager | ||
|
||
// Connection configurations | ||
// | ||
// Optional. Default is nil | ||
Configurations []func(*config.Config) | ||
|
||
// Server username | ||
// | ||
// Optional. Default is "" | ||
Username string | ||
|
||
// Server password | ||
// | ||
// Optional. Default is "" | ||
Password string | ||
|
||
// Node name | ||
// | ||
// Optional. Default is "fiber_storage" | ||
Node string | ||
|
||
// Reset clears any existing keys (Nodes) | ||
// | ||
// Optional. Default is false | ||
Reset bool | ||
|
||
// Time before deleting expired keys (Nodes) | ||
// | ||
// Optional. Default is 10 * time.Second | ||
GCInterval time.Duration | ||
} | ||
|
||
var ConfigDefault = Config{ | ||
URI: "neo4j://localhost", | ||
Node: "fiber_storage", | ||
Reset: false, | ||
GCInterval: 10 * time.Second, | ||
} | ||
|
||
// Helper function to set default values | ||
func configDefault(config ...Config) Config { | ||
|
||
// Return default config if nothing provided | ||
if len(config) < 1 { | ||
return ConfigDefault | ||
} | ||
|
||
// Override default config | ||
cfg := config[0] | ||
|
||
// Set default values | ||
if cfg.URI == "" { | ||
cfg.URI = ConfigDefault.URI | ||
} | ||
|
||
if cfg.Auth == nil { | ||
if cfg.Username != "" && cfg.Password != "" { | ||
cfg.Auth = neo4j.BasicAuth(cfg.Username, cfg.Password, "") | ||
} else { | ||
cfg.Auth = neo4j.NoAuth() | ||
} | ||
} | ||
|
||
if cfg.Node == "" { | ||
cfg.Node = ConfigDefault.Node | ||
} | ||
|
||
if int(cfg.GCInterval.Seconds()) <= 0 { | ||
cfg.GCInterval = ConfigDefault.GCInterval | ||
} | ||
|
||
return cfg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module github.com/gofiber/storage/neo4j | ||
|
||
go 1.23 | ||
|
||
require ( | ||
github.com/neo4j/neo4j-go-driver/v5 v5.27.0 | ||
github.com/stretchr/testify v1.9.0 | ||
github.com/testcontainers/testcontainers-go/modules/neo4j v0.35.0 | ||
) | ||
|
||
require ( | ||
dario.cat/mergo v1.0.0 // indirect | ||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect | ||
github.com/Microsoft/go-winio v0.6.2 // indirect | ||
github.com/cenkalti/backoff/v4 v4.2.1 // indirect | ||
github.com/containerd/containerd v1.7.18 // indirect | ||
github.com/containerd/log v0.1.0 // indirect | ||
github.com/containerd/platforms v0.2.1 // indirect | ||
github.com/cpuguy83/dockercfg v0.3.2 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/distribution/reference v0.6.0 // indirect | ||
github.com/docker/docker v27.1.1+incompatible // indirect | ||
github.com/docker/go-connections v0.5.0 // indirect | ||
github.com/docker/go-units v0.5.0 // indirect | ||
github.com/felixge/httpsnoop v1.0.4 // indirect | ||
github.com/go-logr/logr v1.4.1 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/go-ole/go-ole v1.2.6 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/klauspost/compress v1.17.4 // indirect | ||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/moby/docker-image-spec v1.3.1 // indirect | ||
github.com/moby/patternmatcher v0.6.0 // indirect | ||
github.com/moby/sys/sequential v0.5.0 // indirect | ||
github.com/moby/sys/user v0.1.0 // indirect | ||
github.com/moby/term v0.5.0 // indirect | ||
github.com/morikuni/aec v1.0.0 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.1.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect | ||
github.com/shirou/gopsutil/v3 v3.23.12 // indirect | ||
github.com/shoenig/go-m1cpu v0.1.6 // indirect | ||
github.com/sirupsen/logrus v1.9.3 // indirect | ||
github.com/testcontainers/testcontainers-go v0.35.0 // indirect | ||
github.com/tklauser/go-sysconf v0.3.12 // indirect | ||
github.com/tklauser/numcpus v0.6.1 // indirect | ||
github.com/yusufpapurcu/wmi v1.2.3 // indirect | ||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect | ||
go.opentelemetry.io/otel v1.24.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.24.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.24.0 // indirect | ||
golang.org/x/crypto v0.31.0 // indirect | ||
golang.org/x/sys v0.28.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Grammar Correction for Go Version Note
The note currently reads "Requires latest two release of Golang." Please update it to "Requires latest two releases of Golang" to correct the pluralization.
🧰 Tools
🪛 LanguageTool
[grammar] ~8-~8: After the number ‘two’, use a plural noun. Did you mean “releases”?
Context: ...driver). > Note: Requires latest two release of Golang ### Table of Contents - [...
(CD_NNU)