Skip to content

Commit 568f89a

Browse files
1 parent f2757a6 commit 568f89a

File tree

3 files changed

+473
-1
lines changed

3 files changed

+473
-1
lines changed

storage_versioned_docs/version-s3_v2.x.x/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type Storage interface {
6767
```
6868

6969
## 📑 Storage Implementations
70+
7071
- [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>
7172
- [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>
7273
- [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>
@@ -78,6 +79,7 @@ type Storage interface {
7879
- [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>
7980
- [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>
8081
- [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>
82+
- [Firestore](./firestore/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Firestore%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-firestore.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
8183
- [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>
8284
- [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>
8385
- [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>
@@ -97,4 +99,4 @@ type Storage interface {
9799
- [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>
98100
- [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>
99101
- [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>
100-
- [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>
102+
- [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: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
id: firestore
3+
title: Firestore
4+
---
5+
6+
![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=firestore*)
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-firestore.yml?label=Tests)
9+
10+
A Firestore storage driver using [cloud.google.com/go/firestore](https://pkg.go.dev/cloud.google.com/go/firestore).
11+
12+
**Note:** If no credentials are provided, the driver uses Application Default Credentials (ADC) or the `GOOGLE_APPLICATION_CREDENTIALS` environment variable. If credentials are provided via config (`Credentials` or `CredentialsPath`), those take precedence. See: [Google Cloud Authentication Guide](https://cloud.google.com/docs/authentication)
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 NewFromConnection(client *firestore.Client, collection string) *Storage
27+
func (s *Storage) Get(key string) ([]byte, error)
28+
func (s *Storage) GetWithContext(ctx context.Context, key string) ([]byte, error)
29+
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
30+
func (s *Storage) SetWithContext(ctx context.Context, key string, val []byte, exp time.Duration) error
31+
func (s *Storage) Delete(key string) error
32+
func (s *Storage) DeleteWithContext(ctx context.Context, key string) error
33+
func (s *Storage) Reset() error
34+
func (s *Storage) ResetWithContext(ctx context.Context) error
35+
func (s *Storage) Close() error
36+
func (s *Storage) Conn() *firestore.Client
37+
```
38+
39+
### Installation
40+
41+
Firestore 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:
42+
43+
```bash
44+
go mod init github.com/<user>/<repo>
45+
```
46+
47+
And then install the firestore implementation:
48+
49+
```bash
50+
go get github.com/gofiber/storage/firestore
51+
```
52+
53+
### Examples
54+
55+
Import the storage package.
56+
57+
```go
58+
import firestorage "github.com/gofiber/storage/firestore"
59+
```
60+
61+
You can use the following possibilities to create a storage:
62+
63+
```go
64+
// Initialize with Application Default Credentials
65+
store := firestorage.New(firestorage.Config{
66+
ProjectID: "my-gcp-project",
67+
})
68+
69+
// Initialize with service account JSON file
70+
store := firestorage.New(firestorage.Config{
71+
ProjectID: "my-gcp-project",
72+
CredentialsPath: "/path/to/service-account-key.json",
73+
Collection: "sessions",
74+
})
75+
76+
// Initialize with embedded credentials JSON
77+
store := firestorage.New(firestorage.Config{
78+
ProjectID: "my-gcp-project",
79+
Credentials: `{"type": "service_account", ...}`,
80+
})
81+
82+
// Initialize with custom timeout
83+
store := firestorage.New(firestorage.Config{
84+
ProjectID: "my-gcp-project",
85+
Collection: "fiber_storage",
86+
RequestTimeout: 10 * time.Second,
87+
Reset: false,
88+
})
89+
```
90+
91+
#### Using an Existing Firestore Client
92+
93+
If you already have a Firestore client configured in your application, you can create a Storage instance directly from that client:
94+
95+
```go
96+
import (
97+
"cloud.google.com/go/firestore"
98+
"context"
99+
firestorage "github.com/gofiber/storage/firestore"
100+
)
101+
102+
ctx := context.Background()
103+
client, err := firestore.NewClient(ctx, "my-gcp-project")
104+
if err != nil {
105+
panic(err)
106+
}
107+
108+
store := firestorage.NewFromConnection(client, "my_collection")
109+
```
110+
111+
### Config
112+
113+
```go
114+
type Config struct {
115+
// ProjectID is the Google Cloud project ID
116+
// Required. Will panic if empty
117+
ProjectID string
118+
119+
// Collection name where data will be stored
120+
//
121+
// Optional. Default is "fiber_storage"
122+
Collection string
123+
124+
// CredentialsPath is the path to the service account JSON key file
125+
// If not provided, Application Default Credentials (ADC) will be used
126+
//
127+
// Optional. Default is ""
128+
CredentialsPath string
129+
130+
// Credentials is a JSON string with service account credentials
131+
// Takes precedence over CredentialsPath if both are provided
132+
//
133+
// Optional. Default is ""
134+
Credentials string
135+
136+
// RequestTimeout is the timeout for Firestore requests
137+
//
138+
// Optional. Default is 10 seconds
139+
RequestTimeout time.Duration
140+
141+
// Reset clears all documents in the collection on initialization
142+
//
143+
// Optional. Default is false
144+
Reset bool
145+
}
146+
```
147+
148+
### Default Config
149+
150+
```go
151+
var ConfigDefault = Config{
152+
Collection: "fiber_storage",
153+
RequestTimeout: 10 * time.Second,
154+
Reset: false,
155+
}
156+
```
157+
158+
### Additional Resources
159+
160+
- [Firestore Go SDK Documentation](https://pkg.go.dev/cloud.google.com/go/firestore)
161+
- [Firebase Console](https://console.firebase.google.com)
162+
- [Google Cloud Firestore Documentation](https://cloud.google.com/firestore/docs)
163+
- [Google Cloud Authentication Guide](https://cloud.google.com/docs/authentication)
164+
- [Firestore Quotas and Limits](https://cloud.google.com/firestore/quotas)

0 commit comments

Comments
 (0)