Skip to content

Commit c51ba81

Browse files
1 parent f931ae4 commit c51ba81

File tree

36 files changed

+4389
-0
lines changed

36 files changed

+4389
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
This document contains instructions for migrating to various storage versions.
2+
3+
### 0.1 -> 0.2
4+
v0.2 fixes [a bug](https://github.com/gofiber/fiber/issues/1258) in MYSQL, Postgres and Arangodb in which
5+
inserting non-UTF8 characters would trigger a panic due to the values being saved in a TEXT column instead of a
6+
BYTEA/BLOB column. Migration instructions (note you may need to adjust the table names if you have supplied a custom
7+
config to the storage):
8+
9+
**Postgres**
10+
```sql
11+
ALTER TABLE fiber_storage
12+
ALTER COLUMN v TYPE BYTEA USING v::bytea;
13+
```
14+
15+
**MYSQL**
16+
```sql
17+
ALTER TABLE fiber_storage MODIFY COLUMN v BLOB;
18+
```
19+
20+
**Arangodb**
21+
22+
No migration other then updating the library is necessary.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: 👋 Welcome
3+
description: 📦 Premade storage drivers for 🚀 Fiber.
4+
sidebar_position: 1
5+
---
6+
7+
<p align="center">
8+
<img height="125" alt="Fiber" src="https://github.com/raw/gofiber/storage/master/.github/logo-dark.svg#gh-dark-mode-only" />
9+
<img height="125" alt="Fiber" src="https://github.com/raw/gofiber/storage/master/.github/logo.svg#gh-light-mode-only" />
10+
<br/>
11+
12+
<a href="https://pkg.go.dev/github.com/gofiber/storage?tab=doc">
13+
<img src="https://img.shields.io/badge/%F0%9F%93%9A%20godoc-pkg-00ACD7.svg?color=00ACD7&style=flat"/>
14+
</a>
15+
<a href="https://goreportcard.com/report/github.com/gofiber/storage">
16+
<img src="https://img.shields.io/badge/%F0%9F%93%9D%20goreport-A%2B-75C46B"/>
17+
</a>
18+
<a href="https://gofiber.io/discord">
19+
<img src="https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7"/>
20+
</a>
21+
</p>
22+
23+
Premade storage drivers that implement the [`Storage`](https://github.com/gofiber/storage/blob/main/storage.go) interface, designed to be used with various [Fiber middlewares](https://github.com/gofiber/fiber/tree/master/middleware).
24+
25+
```go
26+
// Storage interface for communicating with different database/key-value
27+
// providers. Visit https://github.com/gofiber/storage for more info.
28+
type Storage interface {
29+
// Get gets the value for the given key.
30+
// `nil, nil` is returned when the key does not exist
31+
Get(key string) ([]byte, error)
32+
33+
// Set stores the given value for the given key along
34+
// with an expiration value, 0 means no expiration.
35+
// Empty key or value will be ignored without an error.
36+
Set(key string, val []byte, exp time.Duration) error
37+
38+
// Delete deletes the value for the given key.
39+
// It returns no error if the storage does not contain the key,
40+
Delete(key string) error
41+
42+
// Reset resets the storage and delete all keys.
43+
Reset() error
44+
45+
// Close closes the storage and will stop any running garbage
46+
// collectors and open connections.
47+
Close() error
48+
}
49+
```
50+
51+
## 📑 Storage Implementations
52+
- [Aerospike](./aerospike/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Aerospike%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-aerospike.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
53+
- [ArangoDB](./arangodb/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+ArangoDB%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-arangodb.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
54+
- [AzureBlob](./azureblob/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Azure+Blob%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-azureblob.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
55+
- [Badger](./badger/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Badger%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-badger.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
56+
- [Bbolt](./bbolt) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Bbolt%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-bbolt.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
57+
- [Cassandra](./cassandra/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Cassandra%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-cassandra.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
58+
- [CloudflareKV](./cloudflarekv/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+CloudflareKV%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-cloudflarekv.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
59+
- [Coherence](./coherence/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Coherence%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-coherence.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
60+
- [Couchbase](./couchbase/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Couchbase%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-couchbase.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
61+
- [DynamoDB](./dynamodb/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+DynamoDB%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-dynamodb.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
62+
- [Etcd](./etcd/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Etcd%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-etcd.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
63+
- [LevelDB](./leveldb/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+LevelDB%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-leveldb.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" alt="LevelDB Tests Status"/> </a>
64+
- [Memcache](./memcache/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Memcache%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-memcache.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
65+
- [Memory](./memory/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Local+Storage%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-memory.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
66+
- [Minio](./minio/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Minio%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-minio.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
67+
- [MockStorage](./mockstorage/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+MockStorage%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mockstorage.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
68+
- [MongoDB](./mongodb/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Mongodb%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mongodb.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
69+
- [MSSQL](./mssql/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+MSSQL%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mssql.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
70+
- [MySQL](./mysql/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+MySQL%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mysql.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
71+
- [NATS](./nats/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests%20Nats%20Driver%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-nats.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
72+
- [Neo4j](./neo4j/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Neo4j%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-neo4j.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
73+
- [Pebble](./pebble/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Pebble%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-pebble.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
74+
- [Postgres](./postgres/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Postgres%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-postgres.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
75+
- [Redis](./redis/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Redis%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-redis.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
76+
- [Rueidis](./rueidis/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+rueidis%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-rueidis.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
77+
- [S3](./s3/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+S3%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-s3.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
78+
- [ScyllaDB](./scylladb/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+scylladb%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-scylladb.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
79+
- [SQLite3](./sqlite3/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Sqlite3%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-sqlite3.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
80+
- [ClickHouse](./clickhouse/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Clickhouse%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-clickhouse.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
81+
- [Valkey](./valkey/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+valkey%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-valkey.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
82+
- [SurrealDB](./surrealdb/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+surrealdb%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-surrealdb.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
id: aerospike
3+
title: Aerospike
4+
---
5+
6+
![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=aerospike*)
7+
[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord)
8+
![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-aerospike.yml?label=Tests)
9+
10+
An Aerospike client driver using `aerospike/aerospike-client-go` and [aerospike/aerospike-client-go](https://github.com/aerospike/aerospike-client-go).
11+
12+
**Note: Requires Go 1.23 and above**
13+
14+
### Table of Contents
15+
16+
- [Signatures](#signatures)
17+
- [Installation](#installation)
18+
- [Examples](#examples)
19+
- [Config](#config)
20+
- [Default Config](#default-config)
21+
22+
### Signatures
23+
24+
```go
25+
func New(config ...Config) Storage
26+
func (s *Storage) Get(key string) ([]byte, error)
27+
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
28+
func (s *Storage) Delete(key string) error
29+
func (s *Storage) Reset() error
30+
func (s *Storage) Close() error
31+
func (s *Storage) Conn() driver.Client
32+
func (s *Storage) GetSchemaInfo() *SchemaInfo
33+
```
34+
35+
### Installation
36+
37+
Aerospike 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:
38+
39+
```bash
40+
go mod init github.com/<user>/<repo>
41+
```
42+
43+
And then install the aerospike implementation:
44+
45+
```bash
46+
go get github.com/gofiber/storage/aerospike
47+
```
48+
49+
### Examples
50+
51+
Import the storage package.
52+
53+
```go
54+
import "github.com/gofiber/storage/aerospike"
55+
```
56+
57+
You can use the following possibilities to create a storage:
58+
59+
```go
60+
// Initialize default config
61+
store := aerospike.New()
62+
63+
// Initialize custom config
64+
store := aerospike.New(aerospike.Config{
65+
Hosts: []*aerospike.Host{aerospike.NewHost("localhost", 3000)},
66+
Namespace: "test", // Default namespace
67+
SetName: "fiber",
68+
Reset: false,
69+
Expiration: 1 * time.Hour,
70+
SchemaVersion: 1,
71+
SchemaDescription: "Default Fiber storage schema",
72+
ForceSchemaUpdate: false,
73+
})
74+
```
75+
76+
### Config
77+
78+
```go
79+
type Config struct {
80+
// Hosts is a list of Aerospike server hosts
81+
Hosts []*aerospike.Host
82+
83+
// Namespace is the Aerospike namespace
84+
Namespace string
85+
86+
// Set is the Aerospike set
87+
SetName string
88+
89+
// Reset clears any existing keys in existing Set
90+
Reset bool
91+
92+
// Expiration is the default expiration time of entries
93+
Expiration time.Duration
94+
95+
// SchemaVersion indicates the schema version to use
96+
SchemaVersion int
97+
98+
// SchemaDescription provides additional info about the schema
99+
SchemaDescription string
100+
101+
// ForceSchemaUpdate forces schema update even if version matches
102+
ForceSchemaUpdate bool
103+
}
104+
```
105+
106+
### Default Config
107+
Used only for optional fields
108+
```go
109+
var ConfigDefault = Config{
110+
Hosts: []*aerospike.Host{aerospike.NewHost("localhost", 3000)},
111+
Namespace: "test", // Default namespace
112+
SetName: "fiber",
113+
Reset: false,
114+
Expiration: 1 * time.Hour,
115+
SchemaVersion: 1,
116+
SchemaDescription: "Default Fiber storage schema",
117+
ForceSchemaUpdate: false,
118+
}
119+
```
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
id: arangodb
3+
title: ArangoDB
4+
---
5+
6+
![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=arangodb*)
7+
[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord)
8+
![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-arangodb.yml?label=Tests)
9+
10+
A ArangoDB storage driver using `arangodb/go-driver` and [arangodb/go-driver](https://github.com/arangodb/go-driver).
11+
12+
**Note: Requires Go 1.19 and above**
13+
14+
### Table of Contents
15+
- [Signatures](#signatures)
16+
- [Installation](#installation)
17+
- [Examples](#examples)
18+
- [Config](#config)
19+
- [Default Config](#default-config)
20+
21+
### Signatures
22+
```go
23+
func New(config ...Config) Storage
24+
func (s *Storage) Get(key string) ([]byte, error)
25+
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
26+
func (s *Storage) Delete(key string) error
27+
func (s *Storage) Reset() error
28+
func (s *Storage) Close() error
29+
func (s *Storage) Conn() driver.Client
30+
```
31+
### Installation
32+
ArangoDB is tested on the 2 last (1.14/1.15) [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet:
33+
```bash
34+
go mod init github.com/<user>/<repo>
35+
```
36+
And then install the arangodb implementation:
37+
```bash
38+
go get github.com/gofiber/storage/arangodb/v2
39+
```
40+
41+
### Examples
42+
Import the storage package.
43+
```go
44+
import "github.com/gofiber/storage/arangodb/v2"
45+
```
46+
47+
You can use the following possibilities to create a storage:
48+
```go
49+
// Initialize default config
50+
store := arangodb.New()
51+
52+
// Initialize custom config
53+
store := arangodb.New(arangodb.Config{
54+
Host: "http://127.0.0.1",
55+
Port: 8529,
56+
Database: "fiber",
57+
Collection: "fiber_storage",
58+
Reset: false,
59+
GCInterval: 10 * time.Second,
60+
})
61+
```
62+
63+
### Config
64+
```go
65+
type Config struct {
66+
// Host name where the DB is hosted
67+
//
68+
// Optional. Default is "http://127.0.0.1"
69+
Host string
70+
71+
// Port where the DB is listening on
72+
//
73+
// Optional. Default is 8529
74+
Port int
75+
76+
// Server username
77+
//
78+
// Optional. Default is ""
79+
Username string
80+
81+
// Server password
82+
//
83+
// Optional. Default is ""
84+
Password string
85+
86+
// Database name
87+
//
88+
// Optional. Default is "fiber"
89+
Database string
90+
91+
// Collection name
92+
//
93+
// Optional. Default is "fiber_storage"
94+
Collection string
95+
96+
// Reset clears any existing keys in existing collection
97+
//
98+
// Optional. Default is false
99+
Reset bool
100+
// Time before deleting expired keys
101+
//
102+
// Optional. Default is 10 * time.Second
103+
GCInterval time.Duration
104+
}
105+
```
106+
107+
### Default Config
108+
Used only for optional fields
109+
```go
110+
var ConfigDefault = Config{
111+
Host: "http://127.0.0.1",
112+
Port: 8529,
113+
Database: "fiber",
114+
Collection: "fiber_storage",
115+
Reset: false,
116+
GCInterval: 10 * time.Second,
117+
}
118+
```

0 commit comments

Comments
 (0)