fix: reviews applied

This commit is contained in:
Yusuf Demir
2025-10-17 03:35:47 +03:00
parent c543c07a8a
commit 1dc1ca69a2
4 changed files with 18 additions and 13 deletions

View File

@@ -22,7 +22,7 @@ A Firestore storage driver using [cloud.google.com/go/firestore](https://pkg.go.
### Signatures
```go
func New(config ...Config) Storage
func New(config ...Config) *Storage
func NewFromConnection(client *firestore.Client, collection string) *Storage
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) GetWithContext(ctx context.Context, key string) ([]byte, error)
@@ -95,9 +95,11 @@ If you already have a Firestore client configured in your application, you can c
```go
import (
"cloud.google.com/go/firestore"
"context"
firestorage "github.com/gofiber/storage/firestore/v2"
)
ctx := context.Background()
client, err := firestore.NewClient(ctx, "my-gcp-project")
if err != nil {
panic(err)

View File

@@ -50,14 +50,11 @@ var ConfigDefault = Config{
// configDefault is a helper function to set default values
func configDefault(config ...Config) Config {
// Return default config if nothing provided
if len(config) < 1 {
return ConfigDefault
var cfg Config
if len(config) > 0 {
cfg = config[0]
}
// Override default config
cfg := config[0]
// Validate required fields
if cfg.ProjectID == "" {
panic("firestore: ProjectID is required")

View File

@@ -11,11 +11,11 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"time"
"cloud.google.com/go/firestore"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@@ -32,7 +32,7 @@ type Storage struct {
type document struct {
Key string `firestore:"k"`
Value []byte `firestore:"v"`
ExpiresAt time.Time `firestore:"exp_at"`
ExpiresAt time.Time `firestore:"exp_at,omitempty"`
}
// New creates a new Firestore storage instance
@@ -197,14 +197,16 @@ func (s *Storage) ResetWithContext(ctx context.Context) error {
for {
doc, err := docs.Next()
if err == io.EOF {
if err == iterator.Done {
break
}
if err != nil {
break
return fmt.Errorf("failed to iterate documents: %w", err)
}
_, _ = bulkWriter.Delete(doc.Ref)
if _, err := bulkWriter.Delete(doc.Ref); err != nil {
return fmt.Errorf("failed to schedule delete for doc %s: %w", doc.Ref.ID, err)
}
}
bulkWriter.Flush()

View File

@@ -39,7 +39,11 @@ func newTestStore(t testing.TB) *Storage {
ContainerRequest: req,
Started: true,
})
testcontainers.CleanupContainer(t, c)
t.Cleanup(func() {
if err := c.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %s", err)
}
})
require.NoError(t, err)
host, err := c.Host(ctx)